WebKit Bugzilla
Attachment 357765 Details for
Bug 192355
: [WHLSL] Add a handwritten parser
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Limit the standard library
bug-192355-20181219172125.patch (text/plain), 359.32 KB, created by
Myles C. Maxfield
on 2018-12-19 17:21:26 PST
(
hide
)
Description:
Limit the standard library
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2018-12-19 17:21:26 PST
Size:
359.32 KB
patch
obsolete
>Subversion Revision: 239402 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index f0e0538cc37cdacd028b60a464214d46e2e1ec31..134332feed3cd03dd9c62d65b735618012d3c6dc 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,305 @@ >+2018-12-19 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ [WHLSL] Add a handwritten parser >+ https://bugs.webkit.org/show_bug.cgi?id=192355 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Test: webgpu/WHLSL/parse.html >+ >+ * DerivedSources.make: >+ * Modules/webgpu/WHLSL/AST/WHLSLASTAnonymousVariableDeclaration.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::AnonymousVariableDeclaration::AnonymousVariableDeclaration): >+ (WebCore::WHLSL::AST::AnonymousVariableDeclaration::origin const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTArrayReferenceType.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::ArrayReferenceType::ArrayReferenceType): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTArrayType.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::ArrayType::ArrayType): >+ (WebCore::WHLSL::AST::ArrayType::numElements const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTAssignmentExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::AssignmentExpression::AssignmentExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBaseFunctionAttribute.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::BaseFunctionAttribute::BaseFunctionAttribute): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBaseSemantic.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::BaseSemantic::BaseSemantic): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBlock.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Block::Block): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBooleanLiteral.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::BooleanLiteral::BooleanLiteral): >+ (WebCore::WHLSL::AST::BooleanLiteral::value const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBreak.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Break::Break): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTBuiltInSemantic.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::BuiltInSemantic::BuiltInSemantic): >+ (WebCore::WHLSL::AST::BuiltInSemantic::variable const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTCallExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::CallExpression::CallExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTCommaExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::CommaExpression::CommaExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpression.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpressionEnumerationMemberReference.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::ConstantExpressionEnumerationMemberReference::ConstantExpressionEnumerationMemberReference): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTContinue.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Continue::Continue): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTDereferenceExpression.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::DereferenceExpression::DereferenceExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTDoWhileLoop.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::DoWhileLoop::DoWhileLoop): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTDotExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::DotExpression::DotExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTEffectfulExpressionStatement.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::EffectfulExpressionStatement::EffectfulExpressionStatement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationDefinition.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::EnumerationDefinition::EnumerationDefinition): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationMember.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::EnumerationMember::EnumerationMember): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTExpression.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Expression::Expression): >+ (WebCore::WHLSL::AST::Expression::origin const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTFallthrough.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Fallthrough::Fallthrough): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTFloatLiteral.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::FloatLiteral::FloatLiteral): >+ (WebCore::WHLSL::AST::FloatLiteral::value const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTForLoop.h: Copied from Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm. >+ (WebCore::WHLSL::AST::ForLoop::ForLoop): >+ (WebCore::WHLSL::AST::ForLoop::~ForLoop): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTFunctionAttribute.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDeclaration.h: Added. >+ (WebCore::WHLSL::AST::FunctionDeclaration::FunctionDeclaration): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeOrigin): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeAttributeBlock): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeEntryPointType): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeType): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeName): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeParameters): >+ (WebCore::WHLSL::AST::FunctionDeclaration::takeSemantic): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDefinition.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::FunctionDefinition::FunctionDefinition): >+ (WebCore::WHLSL::AST::FunctionDefinition::restricted const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTIfStatement.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::IfStatement::IfStatement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTIndexExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::IndexExpression::IndexExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTIntegerLiteral.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::IntegerLiteral::IntegerLiteral): >+ (WebCore::WHLSL::AST::IntegerLiteral::value const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTLogicalExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::LogicalExpression::LogicalExpression): >+ (WebCore::WHLSL::AST::LogicalExpression::type const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTLogicalNotExpression.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::LogicalNotExpression::LogicalNotExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTMakeArrayReferenceExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTMakePointerExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTNativeFunctionDeclaration.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::NativeFunctionDeclaration::NativeFunctionDeclaration): >+ (WebCore::WHLSL::AST::NativeFunctionDeclaration::restricted const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTNativeTypeDeclaration.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::NativeTypeDeclaration::NativeTypeDeclaration): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTNode.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTNullLiteral.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::NullLiteral::NullLiteral): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTNumThreadsFunctionAttribute.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::NumThreadsFunctionAttribute::NumThreadsFunctionAttribute): >+ (WebCore::WHLSL::AST::NumThreadsFunctionAttribute::width const): >+ (WebCore::WHLSL::AST::NumThreadsFunctionAttribute::height const): >+ (WebCore::WHLSL::AST::NumThreadsFunctionAttribute::depth const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTParameter.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Parameter::Parameter): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTPointerType.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::PointerType::PointerType): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTPropertyAccessExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::PropertyAccessExpression::PropertyAccessExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTQualifier.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTReadModifyWriteExpression.h: Added. >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::setNewValueExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::setResultExpression): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::oldVariableReference): >+ (WebCore::WHLSL::AST::ReadModifyWriteExpression::newVariableReference): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTReferenceType.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::ReferenceType::ReferenceType): >+ (WebCore::WHLSL::AST::ReferenceType::origin const): >+ (WebCore::WHLSL::AST::ReferenceType::addressSpace const): >+ (WebCore::WHLSL::AST::ReferenceType::elementType const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTResourceSemantic.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::ResourceSemantic::ResourceSemantic): >+ (WebCore::WHLSL::AST::ResourceSemantic::mode const): >+ (WebCore::WHLSL::AST::ResourceSemantic::index const): >+ (WebCore::WHLSL::AST::ResourceSemantic::space const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTReturn.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Return::Return): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTSemantic.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTSpecializationConstantSemantic.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::SpecializationConstantSemantic::SpecializationConstantSemantic): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTStageInOutSemantic.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::StageInOutSemantic::StageInOutSemantic): >+ (WebCore::WHLSL::AST::StageInOutSemantic::index const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTStatement.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Statement::Statement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTStructureDefinition.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::StructureDefinition::StructureDefinition): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTStructureElement.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::StructureElement::StructureElement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTSwitchCase.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::SwitchCase::SwitchCase): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTSwitchStatement.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::SwitchStatement::SwitchStatement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTTernaryExpression.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::TernaryExpression::TernaryExpression): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTTrap.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Trap::Trap): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTType.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTTypeArgument.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ * Modules/webgpu/WHLSL/AST/WHLSLASTTypeDefinition.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::TypeDefinition::TypeDefinition): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTTypeReference.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::TypeReference::TypeReference): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTUnsignedIntegerLiteral.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::UnsignedIntegerLiteral::UnsignedIntegerLiteral): >+ (WebCore::WHLSL::AST::UnsignedIntegerLiteral::value const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTValue.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::Value::Value): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclaration.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::VariableDeclaration::VariableDeclaration): >+ (WebCore::WHLSL::AST::VariableDeclaration::origin const): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclarationsStatement.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTVariableReference.h: Copied from Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::VariableReference::VariableReference): >+ (WebCore::WHLSL::AST::VariableReference::wrap): >+ * Modules/webgpu/WHLSL/AST/WHLSLASTWhileLoop.h: Copied from Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h. >+ (WebCore::WHLSL::AST::WhileLoop::WhileLoop): >+ * Modules/webgpu/WHLSL/WHLSLLexer.cpp: Added. >+ (WebCore::WHLSL::Lexer::recognizeKeyword): >+ (WebCore::WHLSL::Lexer::consumeTokenFromStream): >+ (WebCore::WHLSL::Lexer::skipWhitespaceAndComments): >+ (WebCore::WHLSL::isWhitespace): >+ (WebCore::WHLSL::isNewline): >+ (WebCore::WHLSL::Lexer::skipWhitespace): >+ (WebCore::WHLSL::Lexer::skipLineComment): >+ (WebCore::WHLSL::Lexer::skipLongComment): >+ (WebCore::WHLSL::Lexer::coreDecimalIntLiteral const): >+ (WebCore::WHLSL::Lexer::decimalIntLiteral const): >+ (WebCore::WHLSL::Lexer::decimalUintLiteral const): >+ (WebCore::WHLSL::isHexadecimalCharacter): >+ (WebCore::WHLSL::Lexer::coreHexadecimalIntLiteral const): >+ (WebCore::WHLSL::Lexer::hexadecimalIntLiteral const): >+ (WebCore::WHLSL::Lexer::hexadecimalUintLiteral const): >+ (WebCore::WHLSL::Lexer::intLiteral const): >+ (WebCore::WHLSL::Lexer::uintLiteral const): >+ (WebCore::WHLSL::Lexer::digit const): >+ (WebCore::WHLSL::Lexer::digitStar const): >+ (WebCore::WHLSL::Lexer::character const): >+ (WebCore::WHLSL::Lexer::coreFloatLiteralType1 const): >+ (WebCore::WHLSL::Lexer::coreFloatLiteral const): >+ (WebCore::WHLSL::Lexer::floatLiteral const): >+ (WebCore::WHLSL::Lexer::validIdentifier const): >+ (WebCore::WHLSL::Lexer::identifier const): >+ (WebCore::WHLSL::Lexer::operatorName const): >+ * Modules/webgpu/WHLSL/WHLSLLexer.h: Added. >+ (WebCore::WHLSL::Lexer::Lexer): >+ (WebCore::WHLSL::Lexer::consumeToken): >+ (WebCore::WHLSL::Lexer::unconsumeToken): >+ (WebCore::WHLSL::Lexer::state const): >+ (WebCore::WHLSL::Lexer::setState): >+ (WebCore::WHLSL::Lexer::isFullyConsumed const): >+ (WebCore::WHLSL::Lexer::string const): >+ (WebCore::WHLSL::Lexer::anyCharacter const): >+ * Modules/webgpu/WHLSL/WHLSLParser.cpp: Added. >+ (WebCore::WHLSL::Parser::Parser): >+ (WebCore::WHLSL::Parser::parse): >+ (WebCore::WHLSL::Parser::peek): >+ (WebCore::WHLSL::Parser::tryType): >+ (WebCore::WHLSL::Parser::tryTypes): >+ (WebCore::WHLSL::Parser::consumeType): >+ (WebCore::WHLSL::Parser::consumeTypes): >+ (WebCore::WHLSL::digitValue): >+ (WebCore::WHLSL::intLiteralToInt): >+ (WebCore::WHLSL::uintLiteralToUint): >+ (WebCore::WHLSL::floatLiteralToFloat): >+ (WebCore::WHLSL::Parser::consumeIntegralLiteral): >+ (WebCore::WHLSL::Parser::consumeNonNegativeIntegralLiteral): >+ (WebCore::WHLSL::recognizeSimpleUnsignedInteger): >+ (WebCore::WHLSL::Parser::parseConstantExpression): >+ (WebCore::WHLSL::Parser::parseTypeArgument): >+ (WebCore::WHLSL::Parser::parseTypeArguments): >+ (WebCore::WHLSL::Parser::parseTypeSuffixAbbreviated): >+ (WebCore::WHLSL::Parser::parseTypeSuffixNonAbbreviated): >+ (WebCore::WHLSL::Parser::parseAddressSpaceType): >+ (WebCore::WHLSL::Parser::parseNonAddressSpaceType): >+ (WebCore::WHLSL::Parser::parseType): >+ (WebCore::WHLSL::Parser::parseTypeDefinition): >+ (WebCore::WHLSL::Parser::parseBuiltInSemantic): >+ (WebCore::WHLSL::Parser::parseResourceSemantic): >+ (WebCore::WHLSL::Parser::parseSpecializationConstantSemantic): >+ (WebCore::WHLSL::Parser::parseStageInOutSemantic): >+ (WebCore::WHLSL::Parser::parseSemantic): >+ (WebCore::WHLSL::Parser::parseQualifiers): >+ (WebCore::WHLSL::Parser::parseStructureElement): >+ (WebCore::WHLSL::Parser::parseStructureDefinition): >+ (WebCore::WHLSL::Parser::parseEnumerationDefinition): >+ (WebCore::WHLSL::Parser::parseEnumerationMember): >+ (WebCore::WHLSL::Parser::parseNativeTypeDeclaration): >+ (WebCore::WHLSL::Parser::parseNumThreadsFunctionAttribute): >+ (WebCore::WHLSL::Parser::parseAttributeBlock): >+ (WebCore::WHLSL::Parser::parseParameter): >+ (WebCore::WHLSL::Parser::parseParameters): >+ (WebCore::WHLSL::Parser::parseFunctionDefinition): >+ (WebCore::WHLSL::Parser::parseEntryPointFunctionDeclaration): >+ (WebCore::WHLSL::Parser::parseRegularFunctionDeclaration): >+ (WebCore::WHLSL::Parser::parseOperatorFunctionDeclaration): >+ (WebCore::WHLSL::Parser::parseFunctionDeclaration): >+ (WebCore::WHLSL::Parser::parseNativeFunctionDeclaration): >+ (WebCore::WHLSL::Parser::parseBlock): >+ (WebCore::WHLSL::Parser::parseBlockBody): >+ (WebCore::WHLSL::Parser::parseIfStatement): >+ (WebCore::WHLSL::Parser::parseSwitchStatement): >+ (WebCore::WHLSL::Parser::parseSwitchCase): >+ (WebCore::WHLSL::Parser::parseForLoop): >+ (WebCore::WHLSL::Parser::parseWhileLoop): >+ (WebCore::WHLSL::Parser::parseDoWhileLoop): >+ (WebCore::WHLSL::Parser::parseVariableDeclaration): >+ (WebCore::WHLSL::Parser::parseVariableDeclarations): >+ (WebCore::WHLSL::Parser::parseStatement): >+ (WebCore::WHLSL::Parser::parseEffectfulExpression): >+ (WebCore::WHLSL::Parser::parseEffectfulAssignment): >+ (WebCore::WHLSL::Parser::parseEffectfulPrefix): >+ (WebCore::WHLSL::Parser::parseEffectfulSuffix): >+ (WebCore::WHLSL::Parser::parseLimitedSuffixOperator): >+ (WebCore::WHLSL::Parser::parseSuffixOperator): >+ (WebCore::WHLSL::Parser::parseExpression): >+ (WebCore::WHLSL::Parser::parseTernaryConditional): >+ (WebCore::WHLSL::Parser::parseAssignment): >+ (WebCore::WHLSL::Parser::parsePossibleTernaryConditional): >+ (WebCore::WHLSL::Parser::parsePossibleLogicalBinaryOperation): >+ (WebCore::WHLSL::Parser::parsePossibleRelationalBinaryOperation): >+ (WebCore::WHLSL::Parser::parsePossibleShift): >+ (WebCore::WHLSL::Parser::parsePossibleAdd): >+ (WebCore::WHLSL::Parser::parsePossibleMultiply): >+ (WebCore::WHLSL::Parser::parsePossiblePrefix): >+ (WebCore::WHLSL::Parser::parsePossibleSuffix): >+ (WebCore::WHLSL::Parser::parseCallExpression): >+ (WebCore::WHLSL::Parser::parseTerm): >+ * Modules/webgpu/WHLSL/WHLSLParser.h: Added. >+ (WebCore::WHLSL::Parser::backtrackingScope): >+ (WebCore::WHLSL::Parser::SuffixExpression::SuffixExpression): >+ (WebCore::WHLSL::Parser::SuffixExpression::operator bool const): >+ * Modules/webgpu/WHLSL/WHLSLProgram.h: Added. >+ (WebCore::WHLSL::Program::append): >+ * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt: Added. >+ * Modules/webgpu/WebGPUDevice.cpp: >+ (WebCore::WebGPUDevice::createShaderModule const): >+ * Modules/webgpu/WebGPUShaderModuleDescriptor.h: >+ * Modules/webgpu/WebGPUShaderModuleDescriptor.idl: >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * platform/graphics/gpu/GPUShaderModuleDescriptor.h: >+ * platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm: >+ (WebCore::GPUShaderModule::create): >+ > 2018-12-18 Ryosuke Niwa <rniwa@webkit.org> > > SVGUseElement::findTarget should return nullptr when there is a cycle >diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make >index 0f297ba74b1e4d5eea0b75fe5d409e19d8872c71..60529ea5e7f7591ec12ebc61f2eda3170f60e310 100644 >--- a/Source/WebCore/DerivedSources.make >+++ b/Source/WebCore/DerivedSources.make >@@ -1596,6 +1596,15 @@ $(GENERATE_SETTINGS_PATTERNS) : $(WebCore)/Scripts/GenerateSettings.rb $(GENERAT > > # -------- > >+# WHLSL Standard Library >+ >+all : WHLSLStandardLibrary.cpp >+ >+WHLSLStandardLibrary.cpp : $(JavaScriptCore_SCRIPTS_DIR)/xxd.pl $(WebCore)/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >+ $(PERL) $(JavaScriptCore_SCRIPTS_DIR)/xxd.pl WHLSLStandardLibrary $(WebCore)/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt WHLSLStandardLibrary.h >+ >+# -------- >+ > # Common generator things > > COMMON_BINDINGS_SCRIPTS = \ >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAnonymousVariableDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAnonymousVariableDeclaration.h >new file mode 100644 >index 0000000000000000000000000000000000000000..fbb9fccc455f31cbf8eb33e47a185022664fda48 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAnonymousVariableDeclaration.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTValue.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class AnonymousVariableDeclaration : public Value { >+public: >+ AnonymousVariableDeclaration(Lexer::Token&& origin) >+ : m_origin(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~AnonymousVariableDeclaration() = default; >+ >+ AnonymousVariableDeclaration(const AnonymousVariableDeclaration&) = delete; >+ AnonymousVariableDeclaration(AnonymousVariableDeclaration&&) = default; >+ >+ Lexer::Token origin() const { return m_origin; } >+ >+private: >+ Lexer::Token m_origin; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayReferenceType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayReferenceType.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2397868353fe2d5a7725f3d9a9a9f638450ee5c2 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayReferenceType.h >@@ -0,0 +1,66 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTReferenceType.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ArrayReferenceType : public ReferenceType { >+public: >+ ArrayReferenceType(Lexer::Token&& origin, String&& addressSpace, std::unique_ptr<Type>&& elementType) >+ : ReferenceType(WTFMove(origin), WTFMove(addressSpace), WTFMove(elementType)) >+ { >+ } >+ >+ virtual ~ArrayReferenceType() = default; >+ >+ ArrayReferenceType(const ArrayReferenceType&) = delete; >+ ArrayReferenceType(ArrayReferenceType&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ return std::make_unique<ArrayReferenceType>(Lexer::Token(origin()), String(addressSpace()), elementType()->clone()); >+ } >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayType.h >new file mode 100644 >index 0000000000000000000000000000000000000000..bf388fb8f6b9a642eeb610f0d7637454abd606f1 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTArrayType.h >@@ -0,0 +1,74 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTType.h" >+#include "WHLSLASTTypeArgument.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ArrayType : public Type { >+public: >+ ArrayType(Lexer::Token&& origin, std::unique_ptr<Type>&& elementType, unsigned numElements) >+ : m_origin(WTFMove(origin)) >+ , m_elementType(WTFMove(elementType)) >+ , m_numElements(numElements) >+ { >+ } >+ >+ virtual ~ArrayType() = default; >+ >+ ArrayType(const ArrayType&) = delete; >+ ArrayType(ArrayType&&) = default; >+ >+ unsigned numElements() const { return m_numElements; } >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ return std::make_unique<ArrayType>(Lexer::Token(m_origin), m_elementType->clone(), m_numElements); >+ } >+ >+private: >+ Lexer::Token m_origin; >+ std::unique_ptr<Type> m_elementType; >+ unsigned m_numElements; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAssignmentExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAssignmentExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c66c6dc35ec3d39993bdb6eb1f33fb00b222d09c >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTAssignmentExpression.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class AssignmentExpression : public Expression { >+public: >+ AssignmentExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& left, std::unique_ptr<Expression>&& right) >+ : Expression(WTFMove(origin)) >+ , m_left(WTFMove(left)) >+ , m_right(WTFMove(right)) >+ { >+ } >+ >+ virtual ~AssignmentExpression() = default; >+ >+ AssignmentExpression(const AssignmentExpression&) = delete; >+ AssignmentExpression(AssignmentExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_left; >+ std::unique_ptr<Expression> m_right; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseFunctionAttribute.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseFunctionAttribute.h >new file mode 100644 >index 0000000000000000000000000000000000000000..69c6511c82b14b49976d1e7bd2062d1fd0eec2fc >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseFunctionAttribute.h >@@ -0,0 +1,61 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class BaseFunctionAttribute : public Node { >+public: >+ BaseFunctionAttribute(Lexer::Token&& origin) >+ : m_origin(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~BaseFunctionAttribute() = default; >+ >+ BaseFunctionAttribute(const BaseFunctionAttribute&) = delete; >+ BaseFunctionAttribute(BaseFunctionAttribute&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..44feceee9b7c003187838d258a78a15504f64de3 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBaseSemantic.h >@@ -0,0 +1,61 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class BaseSemantic : public Node { >+public: >+ BaseSemantic(Lexer::Token&& origin) >+ : m_origin(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~BaseSemantic() = default; >+ >+ BaseSemantic(const BaseSemantic&) = delete; >+ BaseSemantic(BaseSemantic&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBlock.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBlock.h >new file mode 100644 >index 0000000000000000000000000000000000000000..8b73f7f04c4ec3461a18a04c82114a458d5f7267 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBlock.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Block : public Statement { >+public: >+ Block(Lexer::Token&& origin, Vector<std::unique_ptr<Statement>>&& statements) >+ : Statement(WTFMove(origin)) >+ , m_statements(WTFMove(statements)) >+ { >+ } >+ >+ virtual ~Block() = default; >+ >+ Block(const Block&) = delete; >+ Block(Block&&) = default; >+ >+private: >+ Vector<std::unique_ptr<Statement>> m_statements; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBooleanLiteral.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBooleanLiteral.h >new file mode 100644 >index 0000000000000000000000000000000000000000..0c3ba78652e1278524ee3699ac47e34e9b22ffb8 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBooleanLiteral.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class BooleanLiteral : public Expression { >+public: >+ BooleanLiteral(Lexer::Token&& origin, bool value) >+ : Expression(WTFMove(origin)) >+ , m_value(value) >+ { >+ } >+ >+ virtual ~BooleanLiteral() = default; >+ >+ explicit BooleanLiteral(const BooleanLiteral&) = default; >+ BooleanLiteral(BooleanLiteral&&) = default; >+ >+ bool value() const { return m_value; } >+ >+private: >+ bool m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBreak.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBreak.h >new file mode 100644 >index 0000000000000000000000000000000000000000..7c2b10ac72740b53181306006c023629bd88f2dd >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBreak.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Break : public Statement { >+public: >+ Break(Lexer::Token&& origin) >+ : Statement(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Break() = default; >+ >+ Break(const Break&) = delete; >+ Break(Break&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBuiltInSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBuiltInSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ee4012b30427853bcccb265abeda75f1d5cec6de >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTBuiltInSemantic.h >@@ -0,0 +1,83 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBaseSemantic.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class BuiltInSemantic : public BaseSemantic { >+public: >+ enum class Variable { >+ SVInstanceID, >+ SVVertexID, >+ PSize, >+ SVPosition, >+ SVIsFrontFace, >+ SVSampleIndex, >+ SVInnerCoverage, >+ SVTarget, >+ SVDepth, >+ SVCoverage, >+ SVDispatchThreadID, >+ SVGroupID, >+ SVGroupIndex, >+ SVGroupThreadID >+ }; >+ >+ BuiltInSemantic(Lexer::Token&& origin, Variable variable, std::optional<unsigned>&& targetIndex = std::nullopt) >+ : BaseSemantic(WTFMove(origin)) >+ , m_variable(variable) >+ , m_targetIndex(WTFMove(targetIndex)) >+ { >+ } >+ >+ virtual ~BuiltInSemantic() = default; >+ >+ BuiltInSemantic(const BuiltInSemantic&) = delete; >+ BuiltInSemantic(BuiltInSemantic&&) = default; >+ >+ Variable variable() const { return m_variable; } >+ >+private: >+ Variable m_variable; >+ std::optional<unsigned> m_targetIndex; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCallExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCallExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..68af89ead854b2d1533a7549ee4d2e27889f45d2 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCallExpression.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class CallExpression : public Expression { >+public: >+ CallExpression(Lexer::Token&& origin, String&& name, Vector<std::unique_ptr<Expression>>&& arguments) >+ : Expression(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_arguments(WTFMove(arguments)) >+ { >+ } >+ >+ virtual ~CallExpression() = default; >+ >+ CallExpression(const CallExpression&) = delete; >+ CallExpression(CallExpression&&) = default; >+ >+private: >+ String m_name; >+ Vector<std::unique_ptr<Expression>> m_arguments; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCommaExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCommaExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..77bf3dcf50b7356f8ab500cf3a2d63a53e47b314 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTCommaExpression.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class CommaExpression : public Expression { >+public: >+ CommaExpression(Lexer::Token&& origin, Vector<std::unique_ptr<Expression>>&& list) >+ : Expression(WTFMove(origin)) >+ , m_list(WTFMove(list)) >+ { >+ } >+ >+ virtual ~CommaExpression() = default; >+ >+ CommaExpression(const CommaExpression&) = delete; >+ CommaExpression(CommaExpression&&) = default; >+ >+private: >+ Vector<std::unique_ptr<Expression>> m_list; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..8c7d7d060cd81ea92cb17c801a18d9c77389d9d0 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpression.h >@@ -0,0 +1,59 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBooleanLiteral.h" >+#include "WHLSLASTConstantExpressionEnumerationMemberReference.h" >+#include "WHLSLASTFloatLiteral.h" >+#include "WHLSLASTIntegerLiteral.h" >+#include "WHLSLASTNullLiteral.h" >+#include "WHLSLASTUnsignedIntegerLiteral.h" >+#include <wtf/Variant.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+typedef Variant< >+ IntegerLiteral, >+ UnsignedIntegerLiteral, >+ FloatLiteral, >+ NullLiteral, >+ BooleanLiteral, >+ ConstantExpressionEnumerationMemberReference >+ > ConstantExpression; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpressionEnumerationMemberReference.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpressionEnumerationMemberReference.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2c24a98b2cabb0f9ea85c0ba1e090a6608de824f >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTConstantExpressionEnumerationMemberReference.h >@@ -0,0 +1,65 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ConstantExpressionEnumerationMemberReference : public Node { >+public: >+ ConstantExpressionEnumerationMemberReference(Lexer::Token&& origin, String&& left, String&& right) >+ : m_origin(WTFMove(origin)) >+ , m_left(WTFMove(left)) >+ , m_right(WTFMove(right)) >+ { >+ } >+ >+ virtual ~ConstantExpressionEnumerationMemberReference() = default; >+ >+ explicit ConstantExpressionEnumerationMemberReference(const ConstantExpressionEnumerationMemberReference&) = default; >+ ConstantExpressionEnumerationMemberReference(ConstantExpressionEnumerationMemberReference&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+ String m_left; >+ String m_right; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTContinue.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTContinue.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1681024e813c53d0ad2583cb6fe3c24bf5bd260d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTContinue.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Continue : public Statement { >+public: >+ Continue(Lexer::Token&& origin) >+ : Statement(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Continue() = default; >+ >+ Continue(const Continue&) = delete; >+ Continue(Continue&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDereferenceExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDereferenceExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2d2f1717805536b570630ee2da3370258a507ee7 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDereferenceExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class DereferenceExpression : public Expression { >+public: >+ DereferenceExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& pointer) >+ : Expression(WTFMove(origin)) >+ , m_pointer(WTFMove(pointer)) >+ { >+ } >+ >+ virtual ~DereferenceExpression() = default; >+ >+ DereferenceExpression(const DereferenceExpression&) = delete; >+ DereferenceExpression(DereferenceExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_pointer; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDoWhileLoop.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDoWhileLoop.h >new file mode 100644 >index 0000000000000000000000000000000000000000..6cc69c27fea53528ab2ef9d5e068d52024e1701e >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDoWhileLoop.h >@@ -0,0 +1,65 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class DoWhileLoop : public Statement { >+public: >+ DoWhileLoop(Lexer::Token&& origin, std::unique_ptr<Statement>&& body, std::unique_ptr<Expression>&& conditional) >+ : Statement(WTFMove(origin)) >+ , m_body(WTFMove(body)) >+ , m_conditional(WTFMove(conditional)) >+ { >+ } >+ >+ virtual ~DoWhileLoop() = default; >+ >+ DoWhileLoop(const DoWhileLoop&) = delete; >+ DoWhileLoop(DoWhileLoop&&) = default; >+ >+private: >+ std::unique_ptr<Statement> m_body; >+ std::unique_ptr<Expression> m_conditional; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDotExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDotExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..3ecafa2cb2ced72f84c4f97a96349179d7262d2a >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTDotExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTPropertyAccessExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class DotExpression : public PropertyAccessExpression { >+public: >+ DotExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& base, String&& fieldName) >+ : PropertyAccessExpression(WTFMove(origin), WTFMove(base)) >+ , m_fieldName(WTFMove(fieldName)) >+ { >+ } >+ >+ virtual ~DotExpression() = default; >+ >+ DotExpression(const DotExpression&) = delete; >+ DotExpression(DotExpression&&) = default; >+ >+private: >+ String m_fieldName; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEffectfulExpressionStatement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEffectfulExpressionStatement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..fd9aa730804e5e1c0d0e9ceb61b483ba9f6ee673 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEffectfulExpressionStatement.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class EffectfulExpressionStatement : public Statement { >+public: >+ EffectfulExpressionStatement(std::unique_ptr<Expression>&& effectfulExpression) >+ : Statement(Lexer::Token(effectfulExpression->origin())) >+ , m_effectfulExpression(WTFMove(effectfulExpression)) >+ { >+ } >+ >+ virtual ~EffectfulExpressionStatement() = default; >+ >+ EffectfulExpressionStatement(const EffectfulExpressionStatement&) = delete; >+ EffectfulExpressionStatement(EffectfulExpressionStatement&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_effectfulExpression; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationDefinition.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationDefinition.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d607f6620763d9a14dfc0e9bacceac066dc3617d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationDefinition.h >@@ -0,0 +1,76 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTEnumerationMember.h" >+#include "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class EnumerationDefinition : public Type { >+public: >+ EnumerationDefinition(Lexer::Token&& origin, String&& name, std::unique_ptr<Type>&& type, Vector<EnumerationMember> members) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_type(WTFMove(type)) >+ , m_members(WTFMove(members)) >+ { >+ } >+ >+ virtual ~EnumerationDefinition() = default; >+ >+ EnumerationDefinition(const EnumerationDefinition&) = delete; >+ EnumerationDefinition(EnumerationDefinition&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ std::unique_ptr<Type> m_type; >+ Vector<EnumerationMember> m_members; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationMember.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationMember.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1ec91eabe9fb42f9897c83ebf2a2e48c9f0ef216 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTEnumerationMember.h >@@ -0,0 +1,68 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTConstantExpression.h" >+#include "WHLSLASTNode.h" >+#include "WHLSLLexer.h" >+#include <wtf/Optional.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class EnumerationMember : public Node { >+public: >+ EnumerationMember(Lexer::Token&& origin, String&& name, std::optional<ConstantExpression>&& value = std::nullopt) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_value(WTFMove(value)) >+ { >+ } >+ >+ virtual ~EnumerationMember() = default; >+ >+ EnumerationMember(const EnumerationMember&) = delete; >+ EnumerationMember(EnumerationMember&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ std::optional<ConstantExpression> m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..82680321a3175b0b4c218cd68a30dd3fbc8673f2 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTExpression.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTValue.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Expression : public Value { >+public: >+ Expression(Lexer::Token&& origin) >+ : m_origin(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Expression() = default; >+ >+ explicit Expression(const Expression&) = default; >+ Expression(Expression&&) = default; >+ >+ Lexer::Token origin() const { return m_origin; } >+ >+private: >+ Lexer::Token m_origin; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFallthrough.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFallthrough.h >new file mode 100644 >index 0000000000000000000000000000000000000000..f7e3bb50186bd3900bf196402ee8c124a66843a9 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFallthrough.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Fallthrough : public Statement { >+public: >+ Fallthrough(Lexer::Token&& origin) >+ : Statement(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Fallthrough() = default; >+ >+ Fallthrough(const Fallthrough&) = delete; >+ Fallthrough(Fallthrough&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFloatLiteral.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFloatLiteral.h >new file mode 100644 >index 0000000000000000000000000000000000000000..e450bd272895a7ccf34b039884b0603661052488 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFloatLiteral.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class FloatLiteral : public Expression { >+public: >+ FloatLiteral(Lexer::Token&& origin, float value) >+ : Expression(WTFMove(origin)) >+ , m_value(value) >+ { >+ } >+ >+ virtual ~FloatLiteral() = default; >+ >+ explicit FloatLiteral(const FloatLiteral&) = default; >+ FloatLiteral(FloatLiteral&&) = default; >+ >+ float value() const { return m_value; } >+ >+private: >+ float m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTForLoop.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTForLoop.h >new file mode 100644 >index 0000000000000000000000000000000000000000..226063847645d5f07621e68a2e3a9c517f9636ff >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTForLoop.h >@@ -0,0 +1,74 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLASTVariableDeclarationsStatement.h" >+#include "WHLSLLexer.h" >+#include <wtf/Variant.h> >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ForLoop : public Statement { >+public: >+ ForLoop(Lexer::Token&& origin, Variant<VariableDeclarationsStatement, std::unique_ptr<Expression>>&& initialization, std::unique_ptr<Expression>&& condition, std::unique_ptr<Expression>&& increment, std::unique_ptr<Statement>&& body) >+ : Statement(WTFMove(origin)) >+ , m_initialization(WTFMove(initialization)) >+ , m_condition(WTFMove(condition)) >+ , m_increment(WTFMove(increment)) >+ , m_body(WTFMove(body)) >+ { >+ } >+ >+ virtual ~ForLoop() >+ { >+ } >+ >+ ForLoop(const ForLoop&) = delete; >+ ForLoop(ForLoop&&) = default; >+ >+private: >+ Variant<VariableDeclarationsStatement, std::unique_ptr<Expression>> m_initialization; >+ std::unique_ptr<Expression> m_condition; // nullable >+ std::unique_ptr<Expression> m_increment; // nullable >+ std::unique_ptr<Statement> m_body; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionAttribute.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionAttribute.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ec2dff4d606d47b122acad2967de9ac88fc97acd >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionAttribute.h >@@ -0,0 +1,49 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNumThreadsFunctionAttribute.h" >+#include <wtf/Variant.h> >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+typedef Variant<NumThreadsFunctionAttribute> FunctionAttribute; >+typedef Vector<FunctionAttribute> AttributeBlock; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDeclaration.h >new file mode 100644 >index 0000000000000000000000000000000000000000..ff78c4d8b9a6fb009b09b9c105d60c44da5cea5d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDeclaration.h >@@ -0,0 +1,92 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTFunctionAttribute.h" >+#include "WHLSLASTNode.h" >+#include "WHLSLASTParameter.h" >+#include "WHLSLASTSemantic.h" >+#include "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class FunctionDeclaration : public Node { >+public: >+ enum class EntryPointType { >+ Vertex, >+ Fragment, >+ Compute >+ }; >+ >+ FunctionDeclaration(Lexer::Token&& origin, AttributeBlock&& attributeBlock, std::optional<EntryPointType> entryPointType, std::unique_ptr<AST::Type>&& type, String&& name, Parameters&& parameters, std::optional<AST::Semantic>&& semantic) >+ : m_origin(WTFMove(origin)) >+ , m_attributeBlock(WTFMove(attributeBlock)) >+ , m_entryPointType(entryPointType) >+ , m_type(WTFMove(type)) >+ , m_name(WTFMove(name)) >+ , m_parameters(WTFMove(parameters)) >+ , m_semantic(WTFMove(semantic)) >+ { >+ } >+ >+ virtual ~FunctionDeclaration() = default; >+ >+ FunctionDeclaration(const FunctionDeclaration&) = delete; >+ FunctionDeclaration(FunctionDeclaration&&) = default; >+ >+ Lexer::Token&& takeOrigin() { return WTFMove(m_origin); } >+ AttributeBlock&& takeAttributeBlock() { return WTFMove(m_attributeBlock); } >+ std::optional<EntryPointType>&& takeEntryPointType() { return WTFMove(m_entryPointType); } >+ std::unique_ptr<AST::Type>&& takeType() { return WTFMove(m_type); } >+ String&& takeName() { return WTFMove(m_name); } >+ Parameters&& takeParameters() { return WTFMove(m_parameters); } >+ std::optional<AST::Semantic>&& takeSemantic() { return WTFMove(m_semantic); } >+ >+private: >+ Lexer::Token m_origin; >+ AttributeBlock m_attributeBlock; >+ std::optional<EntryPointType> m_entryPointType; >+ std::unique_ptr<AST::Type> m_type; >+ String m_name; >+ Parameters m_parameters; >+ std::optional<AST::Semantic> m_semantic; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDefinition.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDefinition.h >new file mode 100644 >index 0000000000000000000000000000000000000000..8d7209a6c7f2751d889e447541233b8ee641de14 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTFunctionDefinition.h >@@ -0,0 +1,66 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBlock.h" >+#include "WHLSLASTFunctionDeclaration.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class FunctionDefinition : public FunctionDeclaration { >+public: >+ FunctionDefinition(FunctionDeclaration&& functionDeclaration, Block&& block, bool restricted) >+ : FunctionDeclaration(WTFMove(functionDeclaration)) >+ , m_block(WTFMove(block)) >+ , m_restricted(restricted) >+ { >+ } >+ >+ virtual ~FunctionDefinition() = default; >+ >+ FunctionDefinition(const FunctionDefinition&) = delete; >+ FunctionDefinition(FunctionDefinition&&) = default; >+ >+ bool restricted() const { return m_restricted; } >+ >+private: >+ Block m_block; >+ bool m_restricted; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIfStatement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIfStatement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..18131e443b3168299c2f86cd5b9a4f22095513e4 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIfStatement.h >@@ -0,0 +1,67 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class IfStatement : public Statement { >+public: >+ IfStatement(Lexer::Token&& origin, std::unique_ptr<Expression>&& conditional, std::unique_ptr<Statement>&& body, std::unique_ptr<Statement>&& elseBody) >+ : Statement(WTFMove(origin)) >+ , m_conditional(WTFMove(conditional)) >+ , m_body(WTFMove(body)) >+ , m_elseBody(WTFMove(elseBody)) >+ { >+ } >+ >+ virtual ~IfStatement() = default; >+ >+ IfStatement(const IfStatement&) = delete; >+ IfStatement(IfStatement&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_conditional; >+ std::unique_ptr<Statement> m_body; >+ std::unique_ptr<Statement> m_elseBody; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIndexExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIndexExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..0412fa0fdc99a8217101346093a99a9b69ffdebe >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIndexExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTPropertyAccessExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class IndexExpression : public PropertyAccessExpression { >+public: >+ IndexExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& base, std::unique_ptr<Expression>&& index) >+ : PropertyAccessExpression(WTFMove(origin), WTFMove(base)) >+ , m_index(WTFMove(index)) >+ { >+ } >+ >+ virtual ~IndexExpression() = default; >+ >+ IndexExpression(const IndexExpression&) = delete; >+ IndexExpression(IndexExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_index; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIntegerLiteral.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIntegerLiteral.h >new file mode 100644 >index 0000000000000000000000000000000000000000..d6b51d18fceaf5155f94e8865877cfec02c4d0e2 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTIntegerLiteral.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class IntegerLiteral : public Expression { >+public: >+ IntegerLiteral(Lexer::Token&& origin, int value) >+ : Expression(WTFMove(origin)) >+ , m_value(value) >+ { >+ } >+ >+ virtual ~IntegerLiteral() = default; >+ >+ explicit IntegerLiteral(const IntegerLiteral&) = default; >+ IntegerLiteral(IntegerLiteral&&) = default; >+ >+ int value() const { return m_value; } >+ >+private: >+ int m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..77beb1e3b9103eca0d9917665c28aa6b1f71edaf >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalExpression.h >@@ -0,0 +1,73 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class LogicalExpression : public Expression { >+public: >+ enum class Type { >+ And, >+ Or >+ }; >+ >+ LogicalExpression(Lexer::Token&& origin, Type type, std::unique_ptr<Expression>&& left, std::unique_ptr<Expression>&& right) >+ : Expression(WTFMove(origin)) >+ , m_type(type) >+ , m_left(WTFMove(left)) >+ , m_right(WTFMove(right)) >+ { >+ } >+ >+ virtual ~LogicalExpression() = default; >+ >+ LogicalExpression(const LogicalExpression&) = delete; >+ LogicalExpression(LogicalExpression&&) = default; >+ >+ Type type() const { return m_type; } >+ >+private: >+ Type m_type; >+ std::unique_ptr<Expression> m_left; >+ std::unique_ptr<Expression> m_right; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalNotExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalNotExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..8c93d8857613ad5ef7aa2b15de0d960c07061180 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTLogicalNotExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class LogicalNotExpression : public Expression { >+public: >+ LogicalNotExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& operand) >+ : Expression(WTFMove(origin)) >+ , m_operand(WTFMove(operand)) >+ { >+ } >+ >+ virtual ~LogicalNotExpression() = default; >+ >+ LogicalNotExpression(const LogicalNotExpression&) = delete; >+ LogicalNotExpression(LogicalNotExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_operand; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakeArrayReferenceExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakeArrayReferenceExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..10f8206e88a67187cf0d00c6520e65f3730f7b70 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakeArrayReferenceExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class MakeArrayReferenceExpression : public Expression { >+public: >+ MakeArrayReferenceExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& lValue) >+ : Expression(WTFMove(origin)) >+ , m_lValue(WTFMove(lValue)) >+ { >+ } >+ >+ virtual ~MakeArrayReferenceExpression() = default; >+ >+ MakeArrayReferenceExpression(const MakeArrayReferenceExpression&) = delete; >+ MakeArrayReferenceExpression(MakeArrayReferenceExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_lValue; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakePointerExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakePointerExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..69fa9240e10f3ee6537f19cfbf41f74de21c5337 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTMakePointerExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class MakePointerExpression : public Expression { >+public: >+ MakePointerExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& lValue) >+ : Expression(WTFMove(origin)) >+ , m_lValue(WTFMove(lValue)) >+ { >+ } >+ >+ virtual ~MakePointerExpression() = default; >+ >+ MakePointerExpression(const MakePointerExpression&) = delete; >+ MakePointerExpression(MakePointerExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_lValue; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeFunctionDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeFunctionDeclaration.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1a7ea684d0f2801e94b7b943e7d5aa1ce1dd74be >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeFunctionDeclaration.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTFunctionDeclaration.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class NativeFunctionDeclaration : public FunctionDeclaration { >+public: >+ NativeFunctionDeclaration(Lexer::Token&& origin, AttributeBlock&& attributeBlock, std::optional<EntryPointType> entryPointType, std::unique_ptr<AST::Type>&& type, String&& name, Parameters&& parameters, std::optional<AST::Semantic>&& semantic, bool restricted) >+ : FunctionDeclaration(WTFMove(origin), WTFMove(attributeBlock), WTFMove(entryPointType), WTFMove(type), WTFMove(name), WTFMove(parameters), WTFMove(semantic)) >+ , m_restricted(restricted) >+ { >+ } >+ >+ virtual ~NativeFunctionDeclaration() = default; >+ >+ NativeFunctionDeclaration(const NativeFunctionDeclaration&) = delete; >+ NativeFunctionDeclaration(NativeFunctionDeclaration&&) = default; >+ >+ bool restricted() const { return m_restricted; } >+ >+private: >+ bool m_restricted; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeTypeDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeTypeDeclaration.h >new file mode 100644 >index 0000000000000000000000000000000000000000..83f954393c5045ec4277a0f5a2797adedf29786a >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNativeTypeDeclaration.h >@@ -0,0 +1,73 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTType.h" >+#include "WHLSLASTTypeArgument.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class NativeTypeDeclaration : public Type { >+public: >+ NativeTypeDeclaration(Lexer::Token&& origin, String&& name, TypeArguments&& typeArguments) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_typeArguments(WTFMove(typeArguments)) >+ { >+ } >+ >+ virtual ~NativeTypeDeclaration() = default; >+ >+ NativeTypeDeclaration(const NativeTypeDeclaration&) = delete; >+ NativeTypeDeclaration(NativeTypeDeclaration&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ TypeArguments m_typeArguments; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNode.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNode.h >new file mode 100644 >index 0000000000000000000000000000000000000000..f6c4f0060c04d7722fe64b2c31727b54b2b2e166 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNode.h >@@ -0,0 +1,54 @@ >+/* >+ * Copyright (C) 2018 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) >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Node { >+public: >+ Node() = default; >+ >+ virtual ~Node() = default; >+ >+ explicit Node(const Node&) = default; >+ Node(Node&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNullLiteral.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNullLiteral.h >new file mode 100644 >index 0000000000000000000000000000000000000000..5ba7f687e837ddba06b7c78ab53a444286754751 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNullLiteral.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class NullLiteral : public Expression { >+public: >+ NullLiteral(Lexer::Token&& origin) >+ : Expression(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~NullLiteral() = default; >+ >+ explicit NullLiteral(const NullLiteral&) = default; >+ NullLiteral(NullLiteral&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNumThreadsFunctionAttribute.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNumThreadsFunctionAttribute.h >new file mode 100644 >index 0000000000000000000000000000000000000000..eb1681d22a6227f6358e711560d4da10b35a4452 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTNumThreadsFunctionAttribute.h >@@ -0,0 +1,69 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBaseFunctionAttribute.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class NumThreadsFunctionAttribute : public BaseFunctionAttribute { >+public: >+ NumThreadsFunctionAttribute(Lexer::Token&& origin, unsigned width, unsigned height, unsigned depth) >+ : BaseFunctionAttribute(WTFMove(origin)) >+ , m_width(width) >+ , m_height(height) >+ , m_depth(depth) >+ { >+ } >+ >+ virtual ~NumThreadsFunctionAttribute() = default; >+ >+ NumThreadsFunctionAttribute(const NumThreadsFunctionAttribute&) = delete; >+ NumThreadsFunctionAttribute(NumThreadsFunctionAttribute&&) = default; >+ >+ unsigned width() const { return m_width; } >+ unsigned height() const { return m_height; } >+ unsigned depth() const { return m_depth; } >+ >+private: >+ unsigned m_width; >+ unsigned m_height; >+ unsigned m_depth; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTParameter.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTParameter.h >new file mode 100644 >index 0000000000000000000000000000000000000000..6b919fa5753e3f61bbfa21360370b8f0d2db8a26 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTParameter.h >@@ -0,0 +1,76 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTQualifier.h" >+#include "WHLSLASTSemantic.h" >+#include "WHLSLASTType.h" >+#include "WHLSLASTValue.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Parameter : public Value { >+public: >+ Parameter(Lexer::Token&& origin, Qualifiers&& qualifiers, std::unique_ptr<AST::Type>&& type, std::optional<String>&& name, std::optional<AST::Semantic>&& semantic) >+ : m_origin(WTFMove(origin)) >+ , m_qualifiers(WTFMove(qualifiers)) >+ , m_type(WTFMove(type)) >+ , m_name(WTFMove(name)) >+ , m_semantic(WTFMove(semantic)) >+ { >+ } >+ >+ virtual ~Parameter() = default; >+ >+ Parameter(const Parameter&) = delete; >+ Parameter(Parameter&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+ Qualifiers m_qualifiers; >+ std::unique_ptr<AST::Type> m_type; >+ std::optional<String> m_name; >+ std::optional<AST::Semantic> m_semantic; >+}; >+ >+typedef Vector<Parameter> Parameters; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPointerType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPointerType.h >new file mode 100644 >index 0000000000000000000000000000000000000000..4d4bf5cacf58b30367fcccd712e4a62b86d17bf8 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPointerType.h >@@ -0,0 +1,66 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTReferenceType.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class PointerType : public ReferenceType { >+public: >+ PointerType(Lexer::Token&& origin, String&& addressSpace, std::unique_ptr<Type> elementType) >+ : ReferenceType(WTFMove(origin), WTFMove(addressSpace), WTFMove(elementType)) >+ { >+ } >+ >+ virtual ~PointerType() = default; >+ >+ PointerType(const PointerType&) = delete; >+ PointerType(PointerType&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ return std::make_unique<PointerType>(Lexer::Token(origin()), String(addressSpace()), elementType()->clone()); >+ } >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPropertyAccessExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPropertyAccessExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..f12b3b28a21768cd0174743bc307ada97cb791c1 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTPropertyAccessExpression.h >@@ -0,0 +1,62 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class PropertyAccessExpression : public Expression { >+public: >+ PropertyAccessExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& base) >+ : Expression(WTFMove(origin)) >+ , m_base(WTFMove(base)) >+ { >+ } >+ >+ virtual ~PropertyAccessExpression() = default; >+ >+ PropertyAccessExpression(const PropertyAccessExpression&) = delete; >+ PropertyAccessExpression(PropertyAccessExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_base; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTQualifier.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTQualifier.h >new file mode 100644 >index 0000000000000000000000000000000000000000..57fda540729a72cb228570554b050a84fef6c508 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTQualifier.h >@@ -0,0 +1,57 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+enum class Qualifier { >+ Nointerpolation, >+ Noperspective, >+ Uniform, >+ Centroid, >+ Sample >+}; >+ >+typedef Vector<Qualifier> Qualifiers; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReadModifyWriteExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReadModifyWriteExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..3f27e6a3c2c7d4814d5ebbf39aca0d013f2b08ec >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReadModifyWriteExpression.h >@@ -0,0 +1,101 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTAnonymousVariableDeclaration.h" >+#include "WHLSLASTExpression.h" >+#include "WHLSLASTVariableReference.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+/* >+ * 1. Evaluate m_lValue >+ * 2. Assign the result to m_oldValue >+ * 3. Evaluate m_newValueExpression >+ * 4. Assign the result to m_newValue >+ * 5. Assign the result to m_lValue >+ * 6. Evaluate m_resultExpression >+ * 7. Return the result >+ */ >+class ReadModifyWriteExpression : public Expression { >+public: >+ ReadModifyWriteExpression(Lexer::Token&& origin, std::unique_ptr<Expression> lValue) >+ : Expression(Lexer::Token(origin)) >+ , m_lValue(WTFMove(lValue)) >+ , m_oldValue(Lexer::Token(origin)) >+ , m_newValue(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~ReadModifyWriteExpression() = default; >+ >+ ReadModifyWriteExpression(const ReadModifyWriteExpression&) = delete; >+ ReadModifyWriteExpression(ReadModifyWriteExpression&&) = default; >+ >+ void setNewValueExpression(std::unique_ptr<Expression>&& newValueExpression) >+ { >+ m_newValueExpression = WTFMove(newValueExpression); >+ } >+ >+ void setResultExpression(std::unique_ptr<Expression>&& resultExpression) >+ { >+ m_resultExpression = WTFMove(resultExpression); >+ } >+ >+ std::unique_ptr<VariableReference> oldVariableReference() >+ { >+ // The only reason we don't get use-after-frees is the fact that every instance of ReadModifyWriteExpression is allocated on the heap. >+ return std::make_unique<VariableReference>(VariableReference::wrap(m_oldValue)); >+ } >+ >+ std::unique_ptr<VariableReference> newVariableReference() >+ { >+ // The only reason we don't get use-after-frees is the fact that every instance of ReadModifyWriteExpression is allocated on the heap. >+ return std::make_unique<VariableReference>(VariableReference::wrap(m_newValue)); >+ } >+ >+private: >+ std::unique_ptr<Expression> m_lValue; >+ AnonymousVariableDeclaration m_oldValue; >+ AnonymousVariableDeclaration m_newValue; >+ std::unique_ptr<Expression> m_newValueExpression; >+ std::unique_ptr<Expression> m_resultExpression; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReferenceType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReferenceType.h >new file mode 100644 >index 0000000000000000000000000000000000000000..701bbb1ba57df979bf9d09917b9b6bd41486f83b >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReferenceType.h >@@ -0,0 +1,71 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ReferenceType : public Type { >+public: >+ ReferenceType(Lexer::Token&& origin, String&& addressSpace, std::unique_ptr<Type>&& elementType) >+ : m_origin(WTFMove(origin)) >+ , m_addressSpace(WTFMove(addressSpace)) >+ , m_elementType(WTFMove(elementType)) >+ { >+ } >+ >+ virtual ~ReferenceType() = default; >+ >+ ReferenceType(const ReferenceType&) = delete; >+ ReferenceType(ReferenceType&&) = default; >+ >+protected: >+ const Lexer::Token& origin() const { return m_origin; } >+ const String& addressSpace() const { return m_addressSpace; } >+ const std::unique_ptr<Type>& elementType() const { return m_elementType; } >+ >+private: >+ Lexer::Token m_origin; >+ String m_addressSpace; >+ std::unique_ptr<Type> m_elementType; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTResourceSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTResourceSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..811cece3486db42aed610512bbedbe844249b227 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTResourceSemantic.h >@@ -0,0 +1,77 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBaseSemantic.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class ResourceSemantic : public BaseSemantic { >+public: >+ enum class Mode { >+ UnorderedAccessView, >+ Texture, >+ Buffer, >+ Sampler >+ }; >+ >+ ResourceSemantic(Lexer::Token&& origin, Mode mode, unsigned index, unsigned space) >+ : BaseSemantic(WTFMove(origin)) >+ , m_mode(mode) >+ , m_index(index) >+ , m_space(space) >+ { >+ } >+ >+ virtual ~ResourceSemantic() = default; >+ >+ ResourceSemantic(const ResourceSemantic&) = delete; >+ ResourceSemantic(ResourceSemantic&&) = default; >+ >+ Mode mode() const { return m_mode; } >+ unsigned index() const { return m_index; } >+ unsigned space() const { return m_space; } >+ >+private: >+ Mode m_mode; >+ unsigned m_index; >+ unsigned m_space; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReturn.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReturn.h >new file mode 100644 >index 0000000000000000000000000000000000000000..10d786fcec6766f92d0f308d53d18cff9f750801 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTReturn.h >@@ -0,0 +1,63 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Return : public Statement { >+public: >+ Return(Lexer::Token&& origin, std::unique_ptr<Expression>&& value) >+ : Statement(WTFMove(origin)) >+ , m_value(WTFMove(value)) >+ { >+ } >+ >+ virtual ~Return() = default; >+ >+ Return(const Return&) = delete; >+ Return(Return&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..67c0f9ca97c9fe9afde465e7ed42a9c75b27e59e >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSemantic.h >@@ -0,0 +1,50 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBuiltInSemantic.h" >+#include "WHLSLASTResourceSemantic.h" >+#include "WHLSLASTSpecializationConstantSemantic.h" >+#include "WHLSLASTStageInOutSemantic.h" >+#include <wtf/Variant.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+typedef Variant<BuiltInSemantic, ResourceSemantic, SpecializationConstantSemantic, StageInOutSemantic> Semantic; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSpecializationConstantSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSpecializationConstantSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..07d9498c55f104337eb53960ab2ee97129df91e5 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSpecializationConstantSemantic.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBaseSemantic.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class SpecializationConstantSemantic : public BaseSemantic { >+public: >+ SpecializationConstantSemantic(Lexer::Token&& origin) >+ : BaseSemantic(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~SpecializationConstantSemantic() = default; >+ >+ SpecializationConstantSemantic(const SpecializationConstantSemantic&) = delete; >+ SpecializationConstantSemantic(SpecializationConstantSemantic&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStageInOutSemantic.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStageInOutSemantic.h >new file mode 100644 >index 0000000000000000000000000000000000000000..5be924a7309a9804ea46287a39f38907cfc085d4 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStageInOutSemantic.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBaseSemantic.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class StageInOutSemantic : public BaseSemantic { >+public: >+ StageInOutSemantic(Lexer::Token&& origin, unsigned index) >+ : BaseSemantic(WTFMove(origin)) >+ , m_index(index) >+ { >+ } >+ >+ virtual ~StageInOutSemantic() = default; >+ >+ StageInOutSemantic(const StageInOutSemantic&) = delete; >+ StageInOutSemantic(StageInOutSemantic&&) = default; >+ >+ unsigned index() const { return m_index; } >+ >+private: >+ unsigned m_index; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStatement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStatement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..2686edff4d66dbe7ad33fe8f96273420bcb8451d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStatement.h >@@ -0,0 +1,61 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTValue.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Statement : public Value { >+public: >+ Statement(Lexer::Token&& origin) >+ : m_origin(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Statement() = default; >+ >+ Statement(const Statement&) = delete; >+ Statement(Statement&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureDefinition.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureDefinition.h >new file mode 100644 >index 0000000000000000000000000000000000000000..0a8f4a4cc3b05a99f1a9b4e82076f87c18fdf86e >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureDefinition.h >@@ -0,0 +1,74 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStructureElement.h" >+#include "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class StructureDefinition : public Type { >+public: >+ StructureDefinition(Lexer::Token&& origin, String&& name, StructureElements&& structureElements) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_structureElements(WTFMove(structureElements)) >+ { >+ } >+ >+ virtual ~StructureDefinition() = default; >+ >+ StructureDefinition(const StructureDefinition&) = delete; >+ StructureDefinition(StructureDefinition&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ StructureElements m_structureElements; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureElement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureElement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..fc59990f120d0b2fd3a2175b220026fe74c049f5 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTStructureElement.h >@@ -0,0 +1,74 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+#include "WHLSLASTQualifier.h" >+#include "WHLSLASTSemantic.h" >+#include "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class StructureElement : public Node { >+public: >+ StructureElement(Lexer::Token&& origin, Qualifiers&& qualifiers, std::unique_ptr<Type>&& type, String&& name, std::optional<Semantic> semantic) >+ : m_origin(WTFMove(origin)) >+ , m_qualifiers(WTFMove(qualifiers)) >+ , m_type(WTFMove(type)) >+ , m_name(WTFMove(name)) >+ , m_semantic(WTFMove(semantic)) >+ { >+ } >+ >+ virtual ~StructureElement() = default; >+ >+ StructureElement(const StructureElement&) = delete; >+ StructureElement(StructureElement&&) = default; >+ >+private: >+ Lexer::Token m_origin; >+ Qualifiers m_qualifiers; >+ std::unique_ptr<Type> m_type; >+ String m_name; >+ std::optional<Semantic> m_semantic; >+}; >+ >+typedef Vector<StructureElement> StructureElements; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchCase.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchCase.h >new file mode 100644 >index 0000000000000000000000000000000000000000..b44d0ecf74eb01d783471d7c4bd0b9279cb19484 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchCase.h >@@ -0,0 +1,67 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBlock.h" >+#include "WHLSLASTConstantExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+#include <wtf/Optional.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class SwitchCase : public Statement { >+public: >+ SwitchCase(Lexer::Token&& origin, std::optional<ConstantExpression>&& value, Block&& block) >+ : Statement(WTFMove(origin)) >+ , m_value(WTFMove(value)) >+ , m_block(WTFMove(block)) >+ { >+ } >+ >+ virtual ~SwitchCase() = default; >+ >+ SwitchCase(const SwitchCase&) = delete; >+ SwitchCase(SwitchCase&&) = default; >+ >+private: >+ std::optional<ConstantExpression> m_value; >+ Block m_block; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchStatement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchStatement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..736ef1168481738dc07dcc646ec698ccef31d59c >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTSwitchStatement.h >@@ -0,0 +1,66 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLASTSwitchCase.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class SwitchStatement : public Statement { >+public: >+ SwitchStatement(Lexer::Token&& origin, std::unique_ptr<Expression>&& value, Vector<SwitchCase>&& switchCases) >+ : Statement(WTFMove(origin)) >+ , m_value(WTFMove(value)) >+ , m_switchCases(WTFMove(switchCases)) >+ { >+ } >+ >+ virtual ~SwitchStatement() = default; >+ >+ SwitchStatement(const SwitchStatement&) = delete; >+ SwitchStatement(SwitchStatement&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_value; >+ Vector<SwitchCase> m_switchCases; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTernaryExpression.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTernaryExpression.h >new file mode 100644 >index 0000000000000000000000000000000000000000..cbfb5968a6dab9fd335c06f00254e6b66ca60d0d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTernaryExpression.h >@@ -0,0 +1,66 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class TernaryExpression : public Expression { >+public: >+ TernaryExpression(Lexer::Token&& origin, std::unique_ptr<Expression>&& predicate, std::unique_ptr<Expression>&& bodyExpression, std::unique_ptr<Expression>&& elseExpression) >+ : Expression(WTFMove(origin)) >+ , m_predicate(WTFMove(predicate)) >+ , m_bodyExpression(WTFMove(bodyExpression)) >+ , m_elseExpression(WTFMove(elseExpression)) >+ { >+ } >+ >+ virtual ~TernaryExpression() = default; >+ >+ TernaryExpression(const TernaryExpression&) = delete; >+ TernaryExpression(TernaryExpression&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_predicate; >+ std::unique_ptr<Expression> m_bodyExpression; >+ std::unique_ptr<Expression> m_elseExpression; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTrap.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTrap.h >new file mode 100644 >index 0000000000000000000000000000000000000000..577714b2596483e454028258bb835cc4362a6134 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTrap.h >@@ -0,0 +1,60 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Trap : public Statement { >+public: >+ Trap(Lexer::Token&& origin) >+ : Statement(WTFMove(origin)) >+ { >+ } >+ >+ virtual ~Trap() = default; >+ >+ Trap(const Trap&) = delete; >+ Trap(Trap&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTType.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTType.h >new file mode 100644 >index 0000000000000000000000000000000000000000..df6ecec669becef93a8fdf284cce16fd74017521 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTType.h >@@ -0,0 +1,58 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Type : public Node { >+public: >+ Type() = default; >+ >+ virtual ~Type() = default; >+ >+ Type(const Type&) = delete; >+ Type(Type&&) = default; >+ >+ virtual std::unique_ptr<Type> clone() const = 0; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeArgument.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeArgument.h >new file mode 100644 >index 0000000000000000000000000000000000000000..a416896ad4a851582654e708500396c6b0d68c87 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeArgument.h >@@ -0,0 +1,51 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTConstantExpression.h" >+#include "WHLSLLexer.h" >+#include <wtf/Variant.h> >+#include <wtf/Vector.h> >+#include <wtf/text/StringView.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+typedef Variant<ConstantExpression, String> TypeArgument; >+typedef Vector<TypeArgument> TypeArguments; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeDefinition.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeDefinition.h >new file mode 100644 >index 0000000000000000000000000000000000000000..f72c6b6a03d32b79cfe5053ad4cf3fc514549aa8 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeDefinition.h >@@ -0,0 +1,73 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+#include "WHLSLASTType.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class TypeDefinition : public Type { >+public: >+ TypeDefinition(Lexer::Token&& origin, String&& name, std::unique_ptr<AST::Type>&& type) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_type(WTFMove(type)) >+ { >+ } >+ >+ virtual ~TypeDefinition() = default; >+ >+ TypeDefinition(const TypeDefinition&) = delete; >+ TypeDefinition(TypeDefinition&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ std::unique_ptr<AST::Type> m_type; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeReference.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeReference.h >new file mode 100644 >index 0000000000000000000000000000000000000000..6bbab389950b0a4384ebf9d7888a776bafcbe0c4 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTTypeReference.h >@@ -0,0 +1,72 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTType.h" >+#include "WHLSLASTTypeArgument.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class TypeReference : public Type { >+public: >+ TypeReference(Lexer::Token&& origin, String&& name, TypeArguments&& typeArguments) >+ : m_origin(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ , m_typeArguments(WTFMove(typeArguments)) >+ { >+ } >+ >+ virtual ~TypeReference() = default; >+ >+ TypeReference(const TypeReference&) = delete; >+ TypeReference(TypeReference&&) = default; >+ >+ std::unique_ptr<Type> clone() const override >+ { >+ return std::make_unique<TypeReference>(Lexer::Token(m_origin), String(m_name), TypeArguments(m_typeArguments)); >+ } >+ >+private: >+ Lexer::Token m_origin; >+ String m_name; >+ TypeArguments m_typeArguments; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTUnsignedIntegerLiteral.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTUnsignedIntegerLiteral.h >new file mode 100644 >index 0000000000000000000000000000000000000000..67b9c22793a8f11ae2db0c998cb9879c4369e99d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTUnsignedIntegerLiteral.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class UnsignedIntegerLiteral : public Expression { >+public: >+ UnsignedIntegerLiteral(Lexer::Token&& origin, unsigned value) >+ : Expression(WTFMove(origin)) >+ , m_value(value) >+ { >+ } >+ >+ virtual ~UnsignedIntegerLiteral() = default; >+ >+ explicit UnsignedIntegerLiteral(const UnsignedIntegerLiteral&) = default; >+ UnsignedIntegerLiteral(UnsignedIntegerLiteral&&) = default; >+ >+ unsigned value() const { return m_value; } >+ >+private: >+ unsigned m_value; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTValue.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTValue.h >new file mode 100644 >index 0000000000000000000000000000000000000000..bc7067eff72064c6b5b72ff8d6e9fbccbcb3deaf >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTValue.h >@@ -0,0 +1,58 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTNode.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class Value : public Node { >+public: >+ Value() >+ { >+ } >+ >+ virtual ~Value() = default; >+ >+ explicit Value(const Value&) = default; >+ Value(Value&&) = default; >+ >+private: >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclaration.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclaration.h >new file mode 100644 >index 0000000000000000000000000000000000000000..1a9c81ace341f84e85f892d742a8a9757baf76c0 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclaration.h >@@ -0,0 +1,79 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTQualifier.h" >+#include "WHLSLASTSemantic.h" >+#include "WHLSLASTType.h" >+#include "WHLSLASTValue.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class VariableDeclaration : public Value { >+public: >+ VariableDeclaration(Lexer::Token&& origin, Qualifiers&& qualifiers, std::unique_ptr<AST::Type>&& type, String&& name, std::optional<Semantic>&& semantic, std::unique_ptr<Expression>&& initializer) >+ : m_origin(WTFMove(origin)) >+ , m_qualifiers(WTFMove(qualifiers)) >+ , m_type(WTFMove(type)) >+ , m_name(WTFMove(name)) >+ , m_semantic(WTFMove(semantic)) >+ , m_initializer(WTFMove(initializer)) >+ { >+ } >+ >+ virtual ~VariableDeclaration() = default; >+ >+ VariableDeclaration(const VariableDeclaration&) = delete; >+ VariableDeclaration(VariableDeclaration&&) = default; >+ >+ Lexer::Token origin() const { return m_origin; } >+ >+private: >+ Lexer::Token m_origin; >+ Qualifiers m_qualifiers; >+ std::unique_ptr<AST::Type> m_type; >+ String m_name; >+ std::optional<Semantic> m_semantic; >+ std::unique_ptr<Expression> m_initializer; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclarationsStatement.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclarationsStatement.h >new file mode 100644 >index 0000000000000000000000000000000000000000..30be3f45b98797861e14d84a1cb445d10ee6fd0b >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableDeclarationsStatement.h >@@ -0,0 +1,64 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTStatement.h" >+#include "WHLSLASTVariableDeclaration.h" >+#include "WHLSLLexer.h" >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class VariableDeclarationsStatement : public Statement { >+public: >+ VariableDeclarationsStatement(Lexer::Token&& origin, Vector<VariableDeclaration>&& variableDeclarations) >+ : Statement(WTFMove(origin)) >+ , m_variableDeclarations(WTFMove(variableDeclarations)) >+ { >+ } >+ >+ virtual ~VariableDeclarationsStatement() = default; >+ >+ VariableDeclarationsStatement(const VariableDeclarationsStatement&) = delete; >+ VariableDeclarationsStatement(VariableDeclarationsStatement&&) = default; >+ >+private: >+ Vector<VariableDeclaration>&& m_variableDeclarations; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableReference.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableReference.h >new file mode 100644 >index 0000000000000000000000000000000000000000..33b6fc61d5f8d13939aba9055ce937946f7f844f >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTVariableReference.h >@@ -0,0 +1,85 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTAnonymousVariableDeclaration.h" >+#include "WHLSLASTExpression.h" >+#include "WHLSLASTVariableDeclaration.h" >+#include "WHLSLLexer.h" >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class VariableReference : public Expression { >+public: >+ VariableReference(Lexer::Token&& origin, String&& name) >+ : Expression(WTFMove(origin)) >+ , m_name(WTFMove(name)) >+ { >+ } >+ >+ virtual ~VariableReference() = default; >+ >+ VariableReference(const VariableReference&) = delete; >+ VariableReference(VariableReference&&) = default; >+ >+ static VariableReference wrap(VariableDeclaration& variableDeclaration) >+ { >+ VariableReference result(Lexer::Token(variableDeclaration.origin())); >+ result.m_variable = { &variableDeclaration }; >+ return result; >+ } >+ >+ static VariableReference wrap(AnonymousVariableDeclaration& anonymousVariableDeclaration) >+ { >+ VariableReference result(Lexer::Token(anonymousVariableDeclaration.origin())); >+ result.m_variable = { &anonymousVariableDeclaration }; >+ return result; >+ } >+ >+private: >+ VariableReference(Lexer::Token&& origin) >+ : Expression(WTFMove(origin)) >+ { >+ } >+ >+ String m_name; >+ std::optional<Variant<VariableDeclaration*, AnonymousVariableDeclaration*>> m_variable; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTWhileLoop.h b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTWhileLoop.h >new file mode 100644 >index 0000000000000000000000000000000000000000..8aea2c1b2d9f98ed36fcd2b6ffdfa18ba7274839 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLASTWhileLoop.h >@@ -0,0 +1,65 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTExpression.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLLexer.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class WhileLoop : public Statement { >+public: >+ WhileLoop(Lexer::Token&& origin, std::unique_ptr<Expression>&& conditional, std::unique_ptr<Statement>&& body) >+ : Statement(WTFMove(origin)) >+ , m_conditional(WTFMove(conditional)) >+ , m_body(WTFMove(body)) >+ { >+ } >+ >+ virtual ~WhileLoop() = default; >+ >+ WhileLoop(const WhileLoop&) = delete; >+ WhileLoop(WhileLoop&&) = default; >+ >+private: >+ std::unique_ptr<Expression> m_conditional; >+ std::unique_ptr<Statement> m_body; >+}; >+ >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.cpp >index 8708e8146a0a66ef8aaa5515ba4c9ce244e287b6..15bccf38feacb111983c07a8b5e4e881375a69ab 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.cpp >@@ -30,6 +30,8 @@ > #include "config.h" > #include "WHLSLLexer.h" > >+#include <wtf/Optional.h> >+ > namespace WebCore { > > namespace WHLSL { >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..fba42496923c8f738af227e3b6176ebecbd69fb3 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp >@@ -0,0 +1,2552 @@ >+/* >+ * Copyright (C) 2018 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 "config.h" >+#include "WHLSLParser.h" >+ >+#include "WHLSLASTArrayReferenceType.h" >+#include "WHLSLASTArrayType.h" >+#include "WHLSLASTAssignmentExpression.h" >+#include "WHLSLASTBooleanLiteral.h" >+#include "WHLSLASTBreak.h" >+#include "WHLSLASTCallExpression.h" >+#include "WHLSLASTCommaExpression.h" >+#include "WHLSLASTContinue.h" >+#include "WHLSLASTDereferenceExpression.h" >+#include "WHLSLASTDotExpression.h" >+#include "WHLSLASTEffectfulExpressionStatement.h" >+#include "WHLSLASTFallthrough.h" >+#include "WHLSLASTFloatLiteral.h" >+#include "WHLSLASTIndexExpression.h" >+#include "WHLSLASTIntegerLiteral.h" >+#include "WHLSLASTLogicalExpression.h" >+#include "WHLSLASTLogicalNotExpression.h" >+#include "WHLSLASTMakeArrayReferenceExpression.h" >+#include "WHLSLASTMakePointerExpression.h" >+#include "WHLSLASTNullLiteral.h" >+#include "WHLSLASTPointerType.h" >+#include "WHLSLASTQualifier.h" >+#include "WHLSLASTReadModifyWriteExpression.h" >+#include "WHLSLASTReturn.h" >+#include "WHLSLASTTernaryExpression.h" >+#include "WHLSLASTTrap.h" >+#include "WHLSLASTTypeReference.h" >+#include "WHLSLASTUnsignedIntegerLiteral.h" >+#include "WHLSLASTVariableReference.h" >+#include <wtf/text/StringBuilder.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+Parser::Parser() >+{ >+} >+ >+auto Parser::parse(Program& result, StringView stringView, Mode mode) -> std::optional<Error> >+{ >+ m_lexer = Lexer(stringView); >+ m_mode = mode; >+ >+ while (!m_lexer.isFullyConsumed()) { >+ if (tryType(Lexer::Token::Type::Semicolon)) { >+ m_lexer.consumeToken(); >+ continue; >+ } >+ >+ { >+ auto typeDefinition = backtrackingScope<Expected<AST::TypeDefinition, Error>>([&]() { >+ return parseTypeDefinition(); >+ }); >+ if (typeDefinition) { >+ result.append(WTFMove(*typeDefinition)); >+ continue; >+ } >+ } >+ >+ { >+ auto structureDefinition = backtrackingScope<Expected<AST::StructureDefinition, Error>>([&]() { >+ return parseStructureDefinition(); >+ }); >+ if (structureDefinition) { >+ result.append(WTFMove(*structureDefinition)); >+ continue; >+ } >+ } >+ >+ { >+ auto enumerationDefinition = backtrackingScope<Expected<AST::EnumerationDefinition, Error>>([&]() { >+ return parseEnumerationDefinition(); >+ }); >+ if (enumerationDefinition) { >+ result.append(WTFMove(*enumerationDefinition)); >+ continue; >+ } >+ } >+ >+ std::optional<Error> error; >+ { >+ auto functionDefinition = backtrackingScope<Expected<AST::FunctionDefinition, Error>>([&]() { >+ return parseFunctionDefinition(); >+ }); >+ if (functionDefinition) { >+ result.append(WTFMove(*functionDefinition)); >+ continue; >+ } >+ error = functionDefinition.error(); >+ } >+ >+ if (m_mode == Mode::StandardLibrary) { >+ auto nativeFunctionDeclaration = backtrackingScope<Expected<AST::NativeFunctionDeclaration, Error>>([&]() { >+ return parseNativeFunctionDeclaration(); >+ }); >+ if (nativeFunctionDeclaration) { >+ result.append(WTFMove(*nativeFunctionDeclaration)); >+ continue; >+ } >+ } >+ >+ if (m_mode == Mode::StandardLibrary) { >+ auto nativeTypeDeclaration = backtrackingScope<Expected<AST::NativeTypeDeclaration, Error>>([&]() { >+ return parseNativeTypeDeclaration(); >+ }); >+ if (nativeTypeDeclaration) { >+ result.append(WTFMove(*nativeTypeDeclaration)); >+ continue; >+ } >+ } >+ >+ WTFLogAlways("%s", error->error.utf8().data()); >+ return WTFMove(*error); >+ } >+ return std::nullopt; >+} >+ >+auto Parser::fail(const String& message) -> Unexpected<Error> { >+ if (auto nextToken = peek()) >+ return Unexpected<Error>(Error(m_lexer.errorString(*nextToken, message))); >+ return Unexpected<Error>(Error(String::format("Cannot lex: %s", message.utf8().data()))); >+} >+ >+auto Parser::peek() -> Expected<Lexer::Token, Error> { >+ if (auto token = m_lexer.consumeToken()) { >+ m_lexer.unconsumeToken(Lexer::Token(*token)); >+ return *token; >+ } >+ return fail(String("Cannot consume token", String::ConstructFromLiteral)); >+} >+ >+std::optional<Lexer::Token> Parser::tryType(Lexer::Token::Type type) >+{ >+ if (auto token = m_lexer.consumeToken()) { >+ if (token->type == type) >+ return token; >+ m_lexer.unconsumeToken(Lexer::Token(*token)); >+ } >+ return std::nullopt; >+} >+ >+std::optional<Lexer::Token> Parser::tryTypes(Vector<Lexer::Token::Type> types) >+{ >+ if (auto token = m_lexer.consumeToken()) { >+ if (std::find(types.begin(), types.end(), token->type) != types.end()) >+ return token; >+ m_lexer.unconsumeToken(Lexer::Token(*token)); >+ } >+ return std::nullopt; >+} >+ >+auto Parser::consumeType(Lexer::Token::Type type) -> Expected<Lexer::Token, Error> { >+ if (auto token = m_lexer.consumeToken()) { >+ if (token->type == type) >+ return *token; >+ return fail(String::format("Unexpected token (expected %s got %s)", Lexer::Token::typeName(type), Lexer::Token::typeName(token->type))); >+ } >+ return fail(String::format("Cannot consume token (expected %s)", Lexer::Token::typeName(type))); >+} >+ >+auto Parser::consumeTypes(Vector<Lexer::Token::Type> types) -> Expected<Lexer::Token, Error> { >+ auto buildExpectedString = [&]() -> String { >+ StringBuilder builder; >+ builder.append("["); >+ for (unsigned i = 0; i < types.size(); ++i) { >+ if (i > 0) >+ builder.append(", "); >+ builder.append(Lexer::Token::typeName(types[i])); >+ } >+ builder.append("]"); >+ return builder.toString(); >+ }; >+ >+ if (auto token = m_lexer.consumeToken()) { >+ if (std::find(types.begin(), types.end(), token->type) != types.end()) >+ return *token; >+ return fail(String::format("Unexpected token (expected one of %s got %s)", buildExpectedString().utf8().data(), Lexer::Token::typeName(token->type))); >+ } >+ return fail(String::format("Cannot consume token (expected %s)", buildExpectedString().utf8().data())); >+} >+ >+static int digitValue(UChar character) >+{ >+ if (character >= '0' && character <= '9') >+ return character - '0'; >+ if (character >= 'a' && character <= 'f') >+ return character - 'a' + 10; >+ return character - 'A' + 10; >+} >+ >+static Expected<int, Parser::Error> intLiteralToInt(StringView text) >+{ >+ bool negate = false; >+ if (text.startsWith(String("-", String::ConstructFromLiteral))) { >+ negate = true; >+ text = text.substring(1); >+ } >+ int base = 10; >+ if (text.startsWith(String("0x", String::ConstructFromLiteral))) { >+ text = text.substring(2); >+ base = 16; >+ } >+ >+ int result = 0; >+ for (unsigned i = 0; i < text.length(); ++i) { >+ int digit = digitValue(text[i]); >+ auto previous = result; >+ result = result * base + digit; >+ if (result < previous) // FIXME: overflow on signed integers is undefined >+ return Unexpected<Parser::Error>(Parser::Error(String::format("int literal %s is out of bounds", text.utf8().data()))); >+ } >+ if (negate) >+ result *= -1; >+ // FIXME: This algorithm makes it impossible to represent 0x800000 (the most negative representable value) >+ return { result }; >+} >+ >+static Expected<unsigned, Parser::Error> uintLiteralToUint(StringView text) >+{ >+ unsigned base = 10; >+ if (text.startsWith(String("0x", String::ConstructFromLiteral))) { >+ text = text.substring(2); >+ base = 16; >+ } >+ ASSERT(text.substring(text.length() - 1) == "u"); >+ text = text.substring(0, text.length() - 1); >+ unsigned result = 0; >+ for (unsigned i = 0; i < text.length(); ++i) { >+ unsigned digit = digitValue(text[i]); >+ auto previous = result; >+ result = result * base + digit; >+ if (result < previous) >+ return Unexpected<Parser::Error>(Parser::Error(String::format("uint literal %s is out of bounds", text.utf8().data()))); >+ } >+ return { result }; >+} >+ >+static Expected<float, Parser::Error> floatLiteralToFloat(StringView text) >+{ >+ bool negate = false; >+ if (text.length() > 0 && text[0] == '-') { >+ negate = true; >+ text = text.substring(1); >+ } >+ if (text.length() > 0 && text[text.length() - 1] == 'f') >+ text = text.substring(0, text.length() - 1); >+ float result; >+ unsigned index = 0; >+ for (index = 0; index < text.length() && text[index] != '.'; ++index) { >+ ASSERT(text[index] >= '0' && text[index] <= '9'); >+ result = result * 10 + (text[index] - '0'); >+ } >+ ASSERT(index < text.length()); >+ ASSERT(text[index] == '.'); >+ float decimal = 1.0f / 10.0f; >+ for (++index; index < text.length(); ++index) { >+ ASSERT(text[index] >= '0' && text[index] <= '9'); >+ result += decimal * (text[index] - '0'); >+ decimal /= 10.0f; >+ } >+ if (negate) >+ result *= -1; >+ return result; >+} >+ >+auto Parser::consumeIntegralLiteral() -> Expected<Variant<int, unsigned>, Error> { >+ auto integralLiteralToken = consumeTypes({ Lexer::Token::Type::IntLiteral, Lexer::Token::Type::UintLiteral }); >+ if (!integralLiteralToken) >+ return Unexpected<Error>(integralLiteralToken.error()); >+ >+ switch (integralLiteralToken->type) { >+ case Lexer::Token::Type::IntLiteral: { >+ auto result = intLiteralToInt(integralLiteralToken->stringView); >+ if (result) >+ return {{ *result }}; >+ return Unexpected<Error>(result.error()); >+ } >+ case Lexer::Token::Type::UintLiteral: { >+ auto result = uintLiteralToUint(integralLiteralToken->stringView); >+ if (result) >+ return {{ *result }}; >+ return Unexpected<Error>(result.error()); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+auto Parser::consumeNonNegativeIntegralLiteral() -> Expected<unsigned, Error> { >+ auto integralLiteral = consumeIntegralLiteral(); >+ if (!integralLiteral) >+ return Unexpected<Error>(integralLiteral.error()); >+ auto result = WTF::visit(WTF::makeVisitor([](int x) -> std::optional<unsigned> { >+ if (x < 0) >+ return std::nullopt; >+ return x; >+ }, [](unsigned x) -> std::optional<unsigned> { >+ return x; >+ }), *integralLiteral); >+ if (result) >+ return *result; >+ return fail(String("int literal is negative", String::ConstructFromLiteral)); >+} >+ >+static Expected<unsigned, Parser::Error> recognizeSimpleUnsignedInteger(StringView stringView) >+{ >+ unsigned result = 0; >+ if (stringView.length() < 1) >+ return Unexpected<Parser::Error>(Parser::Error(String::format("Simple unsigned literal %s is too short", stringView.utf8().data()))); >+ for (unsigned i = 0; i < stringView.length(); ++i) { >+ if (stringView[i] < '0' || stringView[i] > '9') >+ return Unexpected<Parser::Error>(Parser::Error(String::format("Simple unsigned literal %s isn't of the form [0-9]+", stringView.utf8().data()))); >+ auto previous = result; >+ result = result * 10 + (stringView[i] - '0'); >+ if (result < previous) >+ return Unexpected<Parser::Error>(Parser::Error(String::format("Simple unsigned literal %s is out of bounds", stringView.utf8().data()))); >+ } >+ return result; >+} >+ >+auto Parser::parseConstantExpression() -> Expected<AST::ConstantExpression, Error> { >+ auto type = consumeTypes({ >+ Lexer::Token::Type::IntLiteral, >+ Lexer::Token::Type::UintLiteral, >+ Lexer::Token::Type::FloatLiteral, >+ Lexer::Token::Type::Null, >+ Lexer::Token::Type::True, >+ Lexer::Token::Type::False, >+ Lexer::Token::Type::Identifier, >+ }); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ switch (type->type) { >+ case Lexer::Token::Type::IntLiteral: { >+ auto value = intLiteralToInt(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return {{ AST::IntegerLiteral(WTFMove(*type), *value) }}; >+ } >+ case Lexer::Token::Type::UintLiteral: { >+ auto value = uintLiteralToUint(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return {{ AST::UnsignedIntegerLiteral(WTFMove(*type), *value) }}; >+ } >+ case Lexer::Token::Type::FloatLiteral: { >+ auto value = floatLiteralToFloat(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return {{ AST::FloatLiteral(WTFMove(*type), *value) }}; >+ } >+ case Lexer::Token::Type::Null: >+ return { AST::NullLiteral(WTFMove(*type)) }; >+ case Lexer::Token::Type::True: >+ return { AST::BooleanLiteral(WTFMove(*type), true) }; >+ case Lexer::Token::Type::False: >+ return { AST::BooleanLiteral(WTFMove(*type), false) }; >+ case Lexer::Token::Type::Identifier: { >+ auto origin = consumeType(Lexer::Token::Type::FullStop); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ auto next = consumeType(Lexer::Token::Type::Identifier); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ return { AST::ConstantExpressionEnumerationMemberReference(WTFMove(*origin), type->stringView.toString(), next->stringView.toString()) }; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+auto Parser::parseTypeArgument() -> Expected<AST::TypeArgument, Error> { >+ auto constantExpression = backtrackingScope<Expected<AST::ConstantExpression, Error>>([&]() { >+ return parseConstantExpression(); >+ }); >+ if (constantExpression) >+ return AST::TypeArgument(WTFMove(*constantExpression)); >+ auto result = consumeType(Lexer::Token::Type::Identifier); >+ if (!result) >+ return Unexpected<Error>(result.error()); >+ return AST::TypeArgument(result->stringView.toString()); >+} >+ >+auto Parser::parseTypeArguments() -> Expected<AST::TypeArguments, Error> { >+ auto typeArguments = backtrackingScope<std::optional<AST::TypeArguments>>([&]() -> std::optional<AST::TypeArguments> { >+ auto lessThanSign = consumeType(Lexer::Token::Type::LessThanSign); >+ if (!lessThanSign) >+ return std::nullopt; >+ AST::TypeArguments typeArguments; >+ auto typeArgument = parseTypeArgument(); >+ if (!typeArgument) >+ return std::nullopt; >+ typeArguments.append(WTFMove(*typeArgument)); >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto typeArgument = parseTypeArgument(); >+ if (!typeArgument) >+ return std::nullopt; >+ typeArguments.append(WTFMove(*typeArgument)); >+ } >+ auto greaterThanSign = consumeType(Lexer::Token::Type::GreaterThanSign); >+ if (!greaterThanSign) >+ return std::nullopt; >+ return typeArguments; >+ }); >+ if (typeArguments) >+ return WTFMove(*typeArguments); >+ >+ typeArguments = backtrackingScope<std::optional<AST::TypeArguments>>([&]() -> std::optional<AST::TypeArguments> { >+ auto lessThanSign = consumeType(Lexer::Token::Type::LessThanSign); >+ if (!lessThanSign) >+ return std::nullopt; >+ auto greaterThanSign = consumeType(Lexer::Token::Type::GreaterThanSign); >+ if (!greaterThanSign) >+ return std::nullopt; >+ return {{ }}; >+ }); >+ if (typeArguments) >+ return WTFMove(*typeArguments); >+ >+ return AST::TypeArguments(); >+} >+ >+auto Parser::parseTypeSuffixAbbreviated() -> Expected<TypeSuffixAbbreviated, Error> { >+ auto token = consumeTypes({ Lexer::Token::Type::Star, Lexer::Token::Type::SquareBracketPair, Lexer::Token::Type::LeftSquareBracket }); >+ if (!token) >+ return Unexpected<Error>(token.error()); >+ if (token->type == Lexer::Token::Type::LeftSquareBracket) { >+ auto numElements = consumeNonNegativeIntegralLiteral(); >+ if (!numElements) >+ return Unexpected<Error>(numElements.error()); >+ auto rightSquareBracket = consumeType(Lexer::Token::Type::RightSquareBracket); >+ if (!rightSquareBracket) >+ return Unexpected<Error>(rightSquareBracket.error()); >+ return {{ *token, *numElements }}; >+ } >+ return {{ *token, std::nullopt }}; >+} >+ >+auto Parser::parseTypeSuffixNonAbbreviated() -> Expected<TypeSuffixNonAbbreviated, Error> { >+ auto token = consumeTypes({ Lexer::Token::Type::Star, Lexer::Token::Type::SquareBracketPair, Lexer::Token::Type::LeftSquareBracket }); >+ if (!token) >+ return Unexpected<Error>(token.error()); >+ if (token->type == Lexer::Token::Type::LeftSquareBracket) { >+ auto numElements = consumeNonNegativeIntegralLiteral(); >+ if (!numElements) >+ return Unexpected<Error>(numElements.error()); >+ auto rightSquareBracket = consumeType(Lexer::Token::Type::RightSquareBracket); >+ if (!rightSquareBracket) >+ return Unexpected<Error>(rightSquareBracket.error()); >+ return {{ *token, std::nullopt, *numElements }}; >+ } >+ auto addressSpace = consumeTypes({ Lexer::Token::Type::Constant, Lexer::Token::Type::Device, Lexer::Token::Type::Threadgroup, Lexer::Token::Type::Thread}); >+ if (!addressSpace) >+ return Unexpected<Error>(addressSpace.error()); >+ return {{ *token, { *addressSpace }, std::nullopt }}; >+} >+ >+auto Parser::parseAddressSpaceType() -> Expected<std::unique_ptr<AST::Type>, Error> { >+ auto addressSpace = consumeTypes({ Lexer::Token::Type::Constant, Lexer::Token::Type::Device, Lexer::Token::Type::Threadgroup, Lexer::Token::Type::Thread}); >+ if (!addressSpace) >+ return Unexpected<Error>(addressSpace.error()); >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ auto typeArguments = parseTypeArguments(); >+ if (!typeArguments) >+ return Unexpected<Error>(typeArguments.error()); >+ >+ auto constructTypeFromSuffixAbbreviated = [&](const TypeSuffixAbbreviated& typeSuffixAbbreviated, std::unique_ptr<AST::Type>&& previous) -> std::unique_ptr<AST::Type> { >+ switch (typeSuffixAbbreviated.token.type) { >+ case Lexer::Token::Type::Star: >+ return std::make_unique<AST::PointerType>(Lexer::Token(typeSuffixAbbreviated.token), addressSpace->stringView.toString(), WTFMove(previous)); >+ case Lexer::Token::Type::SquareBracketPair: >+ return std::make_unique<AST::ArrayReferenceType>(Lexer::Token(typeSuffixAbbreviated.token), addressSpace->stringView.toString(), WTFMove(previous)); >+ case Lexer::Token::Type::LeftSquareBracket: >+ return std::make_unique<AST::ArrayType>(Lexer::Token(typeSuffixAbbreviated.token), WTFMove(previous), *typeSuffixAbbreviated.numElements); >+ default: >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ }; >+ >+ auto firstTypeSuffixAbbreviated = parseTypeSuffixAbbreviated(); >+ if (!firstTypeSuffixAbbreviated) >+ return Unexpected<Error>(firstTypeSuffixAbbreviated.error()); >+ std::unique_ptr<AST::Type> result = std::make_unique<AST::TypeReference>(Lexer::Token(*addressSpace), name->stringView.toString(), WTFMove(*typeArguments)); >+ result = constructTypeFromSuffixAbbreviated(*firstTypeSuffixAbbreviated, WTFMove(result)); >+ while (true) { >+ auto typeSuffixAbbreviated = backtrackingScope<Expected<TypeSuffixAbbreviated, Error>>([&]() { >+ return parseTypeSuffixAbbreviated(); >+ }); >+ if (!typeSuffixAbbreviated) >+ break; >+ // FIXME: The nesting here might be in the wrong order. >+ result = constructTypeFromSuffixAbbreviated(*typeSuffixAbbreviated, WTFMove(result)); >+ } >+ >+ return WTFMove(result); >+} >+ >+auto Parser::parseNonAddressSpaceType() -> Expected<std::unique_ptr<AST::Type>, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ auto typeArguments = parseTypeArguments(); >+ if (!typeArguments) >+ return Unexpected<Error>(typeArguments.error()); >+ >+ auto constructTypeFromSuffixNonAbbreviated = [&](const TypeSuffixNonAbbreviated& typeSuffixNonAbbreviated, std::unique_ptr<AST::Type>&& previous) -> std::unique_ptr<AST::Type> { >+ switch (typeSuffixNonAbbreviated.token.type) { >+ case Lexer::Token::Type::Star: >+ return std::make_unique<AST::PointerType>(Lexer::Token(typeSuffixNonAbbreviated.token), typeSuffixNonAbbreviated.addressSpace->stringView.toString(), WTFMove(previous)); >+ case Lexer::Token::Type::SquareBracketPair: >+ return std::make_unique<AST::ArrayReferenceType>(Lexer::Token(typeSuffixNonAbbreviated.token), typeSuffixNonAbbreviated.addressSpace->stringView.toString(), WTFMove(previous)); >+ case Lexer::Token::Type::LeftSquareBracket: >+ return std::make_unique<AST::ArrayType>(Lexer::Token(typeSuffixNonAbbreviated.token), WTFMove(previous), *typeSuffixNonAbbreviated.numElements); >+ default: >+ ASSERT_NOT_REACHED(); >+ return nullptr; >+ } >+ }; >+ >+ std::unique_ptr<AST::Type> result = std::make_unique<AST::TypeReference>(WTFMove(*origin), name->stringView.toString(), WTFMove(*typeArguments)); >+ while (true) { >+ auto typeSuffixNonAbbreviated = backtrackingScope<Expected<TypeSuffixNonAbbreviated, Error>>([&]() { >+ return parseTypeSuffixNonAbbreviated(); >+ }); >+ if (!typeSuffixNonAbbreviated) >+ break; >+ // FIXME: The nesting here might be in the wrong order. >+ result = constructTypeFromSuffixNonAbbreviated(*typeSuffixNonAbbreviated, WTFMove(result)); >+ } >+ >+ return result; >+} >+ >+auto Parser::parseType() -> Expected<std::unique_ptr<AST::Type>, Error> { >+ auto type = backtrackingScope<Expected<std::unique_ptr<AST::Type>, Error>>([&]() { >+ return parseAddressSpaceType(); >+ }); >+ if (type) >+ return type; >+ >+ type = backtrackingScope<Expected<std::unique_ptr<AST::Type>, Error>>([&]() { >+ return parseNonAddressSpaceType(); >+ }); >+ if (type) >+ return type; >+ >+ return Unexpected<Error>(type.error()); >+} >+ >+auto Parser::parseTypeDefinition() -> Expected<AST::TypeDefinition, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Typedef); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ auto equals = consumeType(Lexer::Token::Type::EqualsSign); >+ if (!equals) >+ return Unexpected<Error>(equals.error()); >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ return AST::TypeDefinition(WTFMove(*origin), name->stringView.toString(), WTFMove(*type)); >+} >+ >+auto Parser::parseBuiltInSemantic() -> Expected<AST::BuiltInSemantic, Error> { >+ auto origin = consumeTypes({ >+ Lexer::Token::Type::SVInstanceID, >+ Lexer::Token::Type::SVVertexID, >+ Lexer::Token::Type::PSize, >+ Lexer::Token::Type::SVPosition, >+ Lexer::Token::Type::SVIsFrontFace, >+ Lexer::Token::Type::SVSampleIndex, >+ Lexer::Token::Type::SVInnerCoverage, >+ Lexer::Token::Type::SVTarget, >+ Lexer::Token::Type::SVDepth, >+ Lexer::Token::Type::SVCoverage, >+ Lexer::Token::Type::SVDispatchThreadID, >+ Lexer::Token::Type::SVGroupID, >+ Lexer::Token::Type::SVGroupIndex, >+ Lexer::Token::Type::SVGroupThreadID}); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ switch (origin->type) { >+ case Lexer::Token::Type::SVInstanceID: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVInstanceID); >+ case Lexer::Token::Type::SVVertexID: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVVertexID); >+ case Lexer::Token::Type::PSize: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::PSize); >+ case Lexer::Token::Type::SVPosition: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVPosition); >+ case Lexer::Token::Type::SVIsFrontFace: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVIsFrontFace); >+ case Lexer::Token::Type::SVSampleIndex: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVSampleIndex); >+ case Lexer::Token::Type::SVInnerCoverage: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVInnerCoverage); >+ case Lexer::Token::Type::SVTarget: { >+ auto target = consumeNonNegativeIntegralLiteral(); >+ if (!target) >+ return Unexpected<Error>(target.error()); >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVTarget, *target); >+ } >+ case Lexer::Token::Type::SVDepth: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVDepth); >+ case Lexer::Token::Type::SVCoverage: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVCoverage); >+ case Lexer::Token::Type::SVDispatchThreadID: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVDispatchThreadID); >+ case Lexer::Token::Type::SVGroupID: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVGroupID); >+ case Lexer::Token::Type::SVGroupIndex: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVGroupIndex); >+ case Lexer::Token::Type::SVGroupThreadID: >+ return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVGroupThreadID); >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+auto Parser::parseResourceSemantic() -> Expected<AST::ResourceSemantic, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Register); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto info = consumeType(Lexer::Token::Type::Identifier); >+ if (!info) >+ return Unexpected<Error>(info.error()); >+ if (info->stringView.length() < 2 || (info->stringView[0] != 'u' >+ && info->stringView[0] != 't' >+ && info->stringView[0] != 'b' >+ && info->stringView[0] != 's')) >+ return Unexpected<Error>(Error(String::format("%c is not a known resource type ('u', 't', 'b', or 's')", info->stringView[0]))); >+ >+ AST::ResourceSemantic::Mode mode; >+ switch (info->stringView[0]) { >+ case 'u': >+ mode = AST::ResourceSemantic::Mode::UnorderedAccessView; >+ break; >+ case 't': >+ mode = AST::ResourceSemantic::Mode::Texture; >+ break; >+ case 'b': >+ mode = AST::ResourceSemantic::Mode::Buffer; >+ break; >+ case 's': >+ mode = AST::ResourceSemantic::Mode::Sampler; >+ break; >+ } >+ >+ auto index = recognizeSimpleUnsignedInteger(info->stringView.substring(1)); >+ if (!index) >+ return Unexpected<Error>(index.error()); >+ >+ unsigned space = 0; >+ if (tryType(Lexer::Token::Type::Comma)) { >+ auto spaceToken = consumeType(Lexer::Token::Type::Identifier); >+ if (!spaceToken) >+ return Unexpected<Error>(spaceToken.error()); >+ auto prefix = String("space", String::ConstructFromLiteral); >+ if (!spaceToken->stringView.startsWith(StringView(prefix))) >+ return Unexpected<Error>(Error(String::format("Second argument to resource semantic %s needs be of the form 'space0'", spaceToken->stringView.utf8().data()))); >+ if (spaceToken->stringView.length() <= prefix.length()) >+ return Unexpected<Error>(Error(String::format("Second argument to resource semantic %s needs be of the form 'space0'", spaceToken->stringView.utf8().data()))); >+ auto spaceValue = recognizeSimpleUnsignedInteger(spaceToken->stringView.substring(prefix.length())); >+ if (!spaceValue) >+ return Unexpected<Error>(spaceValue.error()); >+ space = *spaceValue; >+ } >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return AST::ResourceSemantic(WTFMove(*origin), mode, *index, space); >+} >+ >+auto Parser::parseSpecializationConstantSemantic() -> Expected<AST::SpecializationConstantSemantic, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Specialized); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ return AST::SpecializationConstantSemantic(WTFMove(*origin)); >+} >+ >+auto Parser::parseStageInOutSemantic() -> Expected<AST::StageInOutSemantic, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Attribute); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto index = consumeNonNegativeIntegralLiteral(); >+ if (!index) >+ return Unexpected<Error>(index.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return AST::StageInOutSemantic(WTFMove(*origin), *index); >+} >+ >+auto Parser::parseSemantic() -> Expected<AST::Semantic, Error> { >+ auto builtInSemantic = backtrackingScope<Expected<AST::BuiltInSemantic, Error>>([&]() { >+ return parseBuiltInSemantic(); >+ }); >+ if (builtInSemantic) >+ return AST::Semantic(WTFMove(*builtInSemantic)); >+ >+ auto resourceSemantic = backtrackingScope<Expected<AST::ResourceSemantic, Error>>([&]() { >+ return parseResourceSemantic(); >+ }); >+ if (resourceSemantic) >+ return AST::Semantic(WTFMove(*resourceSemantic)); >+ >+ auto specializationConstantSemantic = backtrackingScope<Expected<AST::SpecializationConstantSemantic, Error>>([&]() { >+ return parseSpecializationConstantSemantic(); >+ }); >+ if (specializationConstantSemantic) >+ return AST::Semantic(WTFMove(*specializationConstantSemantic)); >+ >+ auto stageInOutSemantic = backtrackingScope<Expected<AST::StageInOutSemantic, Error>>([&]() { >+ return parseStageInOutSemantic(); >+ }); >+ if (stageInOutSemantic) >+ return AST::Semantic(WTFMove(*stageInOutSemantic)); >+ >+ return Unexpected<Error>(stageInOutSemantic.error()); >+} >+ >+AST::Qualifiers Parser::parseQualifiers() >+{ >+ AST::Qualifiers qualifiers; >+ while (true) { >+ if (auto next = tryType(Lexer::Token::Type::Qualifier)) { >+ if ("nointerpolation" == next->stringView) >+ qualifiers.append(AST::Qualifier::Nointerpolation); >+ else if ("noperspective" == next->stringView) >+ qualifiers.append(AST::Qualifier::Noperspective); >+ else if ("uniform" == next->stringView) >+ qualifiers.append(AST::Qualifier::Uniform); >+ else if ("centroid" == next->stringView) >+ qualifiers.append(AST::Qualifier::Centroid); >+ else if ("sample" == next->stringView) >+ qualifiers.append(AST::Qualifier::Sample); >+ else >+ ASSERT_NOT_REACHED(); >+ } else >+ break; >+ } >+ return qualifiers; >+} >+ >+auto Parser::parseStructureElement() -> Expected<AST::StructureElement, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ AST::Qualifiers qualifiers = parseQualifiers(); >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::StructureElement(WTFMove(*origin), WTFMove(qualifiers), WTFMove(*type), name->stringView.toString(), WTFMove(*semantic)); >+ } >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::StructureElement(WTFMove(*origin), WTFMove(qualifiers), WTFMove(*type), name->stringView.toString(), std::nullopt); >+} >+ >+auto Parser::parseStructureDefinition() -> Expected<AST::StructureDefinition, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Struct); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ auto leftCurlyBracket = consumeType(Lexer::Token::Type::LeftCurlyBracket); >+ if (!leftCurlyBracket) >+ return Unexpected<Error>(leftCurlyBracket.error()); >+ >+ AST::StructureElements structureElements; >+ while (true) { >+ auto structureElement = backtrackingScope<Expected<AST::StructureElement, Error>>([&]() { >+ return parseStructureElement(); >+ }); >+ if (structureElement) >+ structureElements.append(WTFMove(*structureElement)); >+ else >+ break; >+ } >+ >+ auto rightCurlyBracket = consumeType(Lexer::Token::Type::RightCurlyBracket); >+ if (!rightCurlyBracket) >+ return Unexpected<Error>(rightCurlyBracket.error()); >+ >+ return AST::StructureDefinition(WTFMove(*origin), name->stringView.toString(), WTFMove(structureElements)); >+} >+ >+auto Parser::parseEnumerationDefinition() -> Expected<AST::EnumerationDefinition, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Enum); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ std::unique_ptr<AST::Type> type; >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto parsedType = parseType(); >+ if (!parsedType) >+ return Unexpected<Error>(parsedType.error()); >+ type = WTFMove(*parsedType); >+ } >+ >+ auto leftCurlyBracket = consumeType(Lexer::Token::Type::LeftCurlyBracket); >+ if (!leftCurlyBracket) >+ return Unexpected<Error>(leftCurlyBracket.error()); >+ >+ auto firstEnumerationMember = parseEnumerationMember(); >+ if (!firstEnumerationMember) >+ return Unexpected<Error>(firstEnumerationMember.error()); >+ >+ Vector<AST::EnumerationMember> members; >+ members.append(WTFMove(*firstEnumerationMember)); >+ >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto member = parseEnumerationMember(); >+ if (!member) >+ return Unexpected<Error>(member.error()); >+ members.append(WTFMove(*member)); >+ } >+ >+ auto rightCurlyBracket = consumeType(Lexer::Token::Type::RightCurlyBracket); >+ if (!rightCurlyBracket) >+ return Unexpected<Error>(rightCurlyBracket.error()); >+ >+ return AST::EnumerationDefinition(WTFMove(*origin), name->stringView.toString(), WTFMove(type), WTFMove(members)); >+} >+ >+auto Parser::parseEnumerationMember() -> Expected<AST::EnumerationMember, Error> { >+ auto identifier = consumeType(Lexer::Token::Type::Identifier); >+ if (!identifier) >+ return Unexpected<Error>(identifier.error()); >+ auto name = identifier->stringView.toString(); >+ >+ if (tryType(Lexer::Token::Type::EqualsSign)) { >+ auto constantExpression = parseConstantExpression(); >+ if (!constantExpression) >+ return Unexpected<Error>(constantExpression.error()); >+ return AST::EnumerationMember(Lexer::Token(*identifier), WTFMove(name), WTFMove(*constantExpression)); >+ } >+ return AST::EnumerationMember(Lexer::Token(*identifier), WTFMove(name)); >+} >+ >+auto Parser::parseNativeTypeDeclaration() -> Expected<AST::NativeTypeDeclaration, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Native); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto parsedTypedef = consumeType(Lexer::Token::Type::Typedef); >+ if (!parsedTypedef) >+ return Unexpected<Error>(parsedTypedef.error()); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ auto typeArguments = parseTypeArguments(); >+ if (!typeArguments) >+ return Unexpected<Error>(typeArguments.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::NativeTypeDeclaration(WTFMove(*origin), name->stringView.toString(), WTFMove(*typeArguments)); >+} >+ >+auto Parser::parseNumThreadsFunctionAttribute() -> Expected<AST::NumThreadsFunctionAttribute, Error> { >+ auto origin = consumeType(Lexer::Token::Type::NumThreads); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto width = consumeNonNegativeIntegralLiteral(); >+ if (!width) >+ return Unexpected<Error>(width.error()); >+ >+ auto comma = consumeType(Lexer::Token::Type::Comma); >+ if (!comma) >+ return Unexpected<Error>(comma.error()); >+ >+ auto height = consumeNonNegativeIntegralLiteral(); >+ if (!height) >+ return Unexpected<Error>(height.error()); >+ >+ comma = consumeType(Lexer::Token::Type::Comma); >+ if (!comma) >+ return Unexpected<Error>(comma.error()); >+ >+ auto depth = consumeNonNegativeIntegralLiteral(); >+ if (!depth) >+ return Unexpected<Error>(depth.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return AST::NumThreadsFunctionAttribute(WTFMove(*origin), *width, *height, *depth); >+} >+ >+auto Parser::parseAttributeBlock() -> Expected<AST::AttributeBlock, Error> { >+ auto leftSquareBracket = consumeType(Lexer::Token::Type::LeftSquareBracket); >+ if (!leftSquareBracket) >+ return Unexpected<Error>(leftSquareBracket.error()); >+ >+ AST::AttributeBlock result; >+ >+ while (true) { >+ auto numThreadsFunctionAttribute = backtrackingScope<Expected<AST::NumThreadsFunctionAttribute, Error>>([&]() { >+ return parseNumThreadsFunctionAttribute(); >+ }); >+ if (numThreadsFunctionAttribute) { >+ result.append(WTFMove(*numThreadsFunctionAttribute)); >+ continue; >+ } >+ >+ break; >+ } >+ >+ auto rightSquareBracket = consumeType(Lexer::Token::Type::RightSquareBracket); >+ if (!rightSquareBracket) >+ return Unexpected<Error>(rightSquareBracket.error()); >+ >+ return result; >+} >+ >+auto Parser::parseParameter() -> Expected<AST::Parameter, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ AST::Qualifiers qualifiers = parseQualifiers(); >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ std::optional<String> name; >+ if (auto token = tryType(Lexer::Token::Type::Identifier)) >+ name = token->stringView.toString(); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ return AST::Parameter(WTFMove(*origin), WTFMove(qualifiers), WTFMove(*type), WTFMove(name), WTFMove(*semantic)); >+ } >+ >+ return AST::Parameter(WTFMove(*origin), WTFMove(qualifiers), WTFMove(*type), WTFMove(name), std::nullopt); >+} >+ >+auto Parser::parseParameters() -> Expected<AST::Parameters, Error> { >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ AST::Parameters parameters; >+ if (tryType(Lexer::Token::Type::RightParenthesis)) >+ return parameters; >+ >+ auto firstParameter = parseParameter(); >+ if (!firstParameter) >+ return Unexpected<Error>(firstParameter.error()); >+ parameters.append(WTFMove(*firstParameter)); >+ >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto parameter = parseParameter(); >+ if (!parameter) >+ return Unexpected<Error>(parameter.error()); >+ parameters.append(WTFMove(*parameter)); >+ } >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return parameters; >+} >+ >+auto Parser::parseFunctionDefinition() -> Expected<AST::FunctionDefinition, Error> { >+ bool restricted = static_cast<bool>(tryType(Lexer::Token::Type::Restricted)); >+ >+ auto functionDeclaration = parseFunctionDeclaration(); >+ if (!functionDeclaration) >+ return Unexpected<Error>(functionDeclaration.error()); >+ >+ auto block = parseBlock(); >+ if (!block) >+ return Unexpected<Error>(block.error()); >+ >+ return AST::FunctionDefinition(WTFMove(*functionDeclaration), WTFMove(*block), restricted); >+} >+ >+auto Parser::parseEntryPointFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ AST::AttributeBlock attributeBlock; >+ AST::FunctionDeclaration::EntryPointType entryPointType; >+ >+ auto parsedAttributeBlock = backtrackingScope<Expected<AST::AttributeBlock, Error>>([&]() { >+ return parseAttributeBlock(); >+ }); >+ if (parsedAttributeBlock) { >+ auto compute = consumeType(Lexer::Token::Type::Compute); >+ if (!compute) >+ return Unexpected<Error>(compute.error()); >+ attributeBlock = WTFMove(*parsedAttributeBlock); >+ entryPointType = AST::FunctionDeclaration::EntryPointType::Compute; >+ } else { >+ auto type = consumeTypes({ Lexer::Token::Type::Vertex, Lexer::Token::Type::Fragment }); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ switch (origin->type) { >+ case Lexer::Token::Type::Vertex: >+ entryPointType = AST::FunctionDeclaration::EntryPointType::Vertex; >+ break; >+ case Lexer::Token::Type::Fragment: >+ entryPointType = AST::FunctionDeclaration::EntryPointType::Fragment; >+ break; >+ default: >+ ASSERT_NOT_REACHED(); >+ entryPointType = AST::FunctionDeclaration::EntryPointType::Vertex; >+ } >+ } >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ auto parameters = parseParameters(); >+ if (!parameters) >+ return Unexpected<Error>(parameters.error()); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ return AST::FunctionDeclaration(WTFMove(*origin), WTFMove(attributeBlock), entryPointType, WTFMove(*type), name->stringView.toString(), WTFMove(*parameters), WTFMove(*semantic)); >+ } >+ >+ return AST::FunctionDeclaration(WTFMove(*origin), WTFMove(attributeBlock), entryPointType, WTFMove(*type), name->stringView.toString(), WTFMove(*parameters), std::nullopt); >+} >+ >+auto Parser::parseRegularFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ auto name = consumeTypes({ Lexer::Token::Type::Identifier, Lexer::Token::Type::OperatorName }); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ auto parameters = parseParameters(); >+ if (!parameters) >+ return Unexpected<Error>(parameters.error()); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ return AST::FunctionDeclaration(WTFMove(*origin), { }, std::nullopt, WTFMove(*type), name->stringView.toString(), WTFMove(*parameters), WTFMove(*semantic)); >+ } >+ >+ return AST::FunctionDeclaration(WTFMove(*origin), { }, std::nullopt, WTFMove(*type), name->stringView.toString(), WTFMove(*parameters), std::nullopt); >+} >+ >+auto Parser::parseOperatorFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Operator); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ auto parameters = parseParameters(); >+ if (!parameters) >+ return Unexpected<Error>(parameters.error()); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ return AST::FunctionDeclaration(WTFMove(*origin), { }, std::nullopt, WTFMove(*type), String("Operator Cast", String::ConstructFromLiteral), WTFMove(*parameters), WTFMove(*semantic)); >+ } >+ >+ return AST::FunctionDeclaration(WTFMove(*origin), { }, std::nullopt, WTFMove(*type), String("Operator Cast", String::ConstructFromLiteral), WTFMove(*parameters), std::nullopt); >+} >+ >+auto Parser::parseFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error> { >+ auto entryPointFunctionDeclaration = backtrackingScope<Expected<AST::FunctionDeclaration, Error>>([&]() { >+ return parseEntryPointFunctionDeclaration(); >+ }); >+ if (entryPointFunctionDeclaration) >+ return WTFMove(*entryPointFunctionDeclaration); >+ >+ auto regularFunctionDeclaration = backtrackingScope<Expected<AST::FunctionDeclaration, Error>>([&]() { >+ return parseRegularFunctionDeclaration(); >+ }); >+ if (regularFunctionDeclaration) >+ return WTFMove(*regularFunctionDeclaration); >+ >+ auto operatorFunctionDeclaration = backtrackingScope<Expected<AST::FunctionDeclaration, Error>>([&]() { >+ return parseOperatorFunctionDeclaration(); >+ }); >+ if (operatorFunctionDeclaration) >+ return WTFMove(*operatorFunctionDeclaration); >+ >+ return Unexpected<Error>(operatorFunctionDeclaration.error()); >+} >+ >+auto Parser::parseNativeFunctionDeclaration() -> Expected<AST::NativeFunctionDeclaration, Error> { >+ std::optional<Lexer::Token> origin; >+ >+ bool restricted = false; >+ if (auto restrictedValue = tryType(Lexer::Token::Type::Restricted)) { >+ origin = *restrictedValue; >+ restricted = true; >+ } >+ >+ auto native = consumeType(Lexer::Token::Type::Native); >+ if (!native) >+ return Unexpected<Error>(native.error()); >+ if (!origin) >+ origin = *native; >+ >+ auto functionDeclaration = parseFunctionDeclaration(); >+ if (!functionDeclaration) >+ return Unexpected<Error>(functionDeclaration.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::NativeFunctionDeclaration(functionDeclaration->takeOrigin(), functionDeclaration->takeAttributeBlock(), functionDeclaration->takeEntryPointType(), functionDeclaration->takeType(), functionDeclaration->takeName(), functionDeclaration->takeParameters(), functionDeclaration->takeSemantic(), restricted); >+} >+ >+auto Parser::parseBlock() -> Expected<AST::Block, Error> { >+ auto origin = consumeType(Lexer::Token::Type::LeftCurlyBracket); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto result = parseBlockBody(WTFMove(*origin)); >+ >+ auto rightCurlyBracket = consumeType(Lexer::Token::Type::RightCurlyBracket); >+ if (!rightCurlyBracket) >+ return Unexpected<Error>(rightCurlyBracket.error()); >+ >+ return WTFMove(result); >+} >+ >+AST::Block Parser::parseBlockBody(Lexer::Token&& origin) >+{ >+ Vector<std::unique_ptr<AST::Statement>> statements; >+ while (true) { >+ auto statement = backtrackingScope<Expected<std::unique_ptr<AST::Statement>, Error>>([&]() { >+ return parseStatement(); >+ }); >+ if (statement) >+ statements.append(WTFMove(*statement)); >+ else >+ break; >+ } >+ return AST::Block(WTFMove(origin), WTFMove(statements)); >+} >+ >+auto Parser::parseIfStatement() -> Expected<AST::IfStatement, Error> { >+ auto origin = consumeType(Lexer::Token::Type::If); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto conditional = parseExpression(); >+ if (!conditional) >+ return Unexpected<Error>(conditional.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ auto body = parseStatement(); >+ if (!body) >+ return Unexpected<Error>(body.error()); >+ >+ std::unique_ptr<AST::Statement> elseBody; >+ if (tryType(Lexer::Token::Type::Else)) { >+ auto parsedElseBody = parseStatement(); >+ if (!parsedElseBody) >+ return Unexpected<Error>(parsedElseBody.error()); >+ elseBody = WTFMove(*parsedElseBody); >+ } >+ >+ return AST::IfStatement(WTFMove(*origin), WTFMove(*conditional), WTFMove(*body), WTFMove(elseBody)); >+} >+ >+auto Parser::parseSwitchStatement() -> Expected<AST::SwitchStatement, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Switch); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto value = parseExpression(); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ auto leftCurlyBracket = consumeType(Lexer::Token::Type::LeftCurlyBracket); >+ if (!leftCurlyBracket) >+ return Unexpected<Error>(leftCurlyBracket.error()); >+ >+ Vector<AST::SwitchCase> switchCases; >+ while (true) { >+ auto switchCase = backtrackingScope<Expected<AST::SwitchCase, Error>>([&]() { >+ return parseSwitchCase(); >+ }); >+ if (switchCase) >+ switchCases.append(WTFMove(*switchCase)); >+ else >+ break; >+ } >+ >+ auto rightCurlyBracket = consumeType(Lexer::Token::Type::RightCurlyBracket); >+ if (!rightCurlyBracket) >+ return Unexpected<Error>(rightCurlyBracket.error()); >+ >+ return AST::SwitchStatement(WTFMove(*origin), WTFMove(*value), WTFMove(switchCases)); >+} >+ >+auto Parser::parseSwitchCase() -> Expected<AST::SwitchCase, Error> { >+ auto origin = consumeTypes({ Lexer::Token::Type::Case, Lexer::Token::Type::Default }); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ switch (origin->type) { >+ case Lexer::Token::Type::Case: { >+ auto value = parseConstantExpression(); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ >+ auto origin = consumeType(Lexer::Token::Type::Colon); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto block = parseBlockBody(Lexer::Token(*origin)); >+ >+ return AST::SwitchCase(WTFMove(*origin), WTFMove(*value), WTFMove(block)); >+ } >+ case Lexer::Token::Type::Default: { >+ auto origin = consumeType(Lexer::Token::Type::Colon); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto block = parseBlockBody(Lexer::Token(*origin)); >+ >+ return AST::SwitchCase(WTFMove(*origin), std::nullopt, WTFMove(block)); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+auto Parser::parseForLoop() -> Expected<AST::ForLoop, Error> { >+ auto origin = consumeType(Lexer::Token::Type::For); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto parseRemainder = [&](Variant<AST::VariableDeclarationsStatement, std::unique_ptr<AST::Expression>>&& initialization) -> Expected<AST::ForLoop, Error> { >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ auto condition = backtrackingScope<std::unique_ptr<AST::Expression>>([&]() -> std::unique_ptr<AST::Expression> { >+ if (auto expression = parseExpression()) >+ return WTFMove(*expression); >+ return nullptr; >+ }); >+ >+ semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ auto increment = backtrackingScope<std::unique_ptr<AST::Expression>>([&]() -> std::unique_ptr<AST::Expression> { >+ if (auto expression = parseExpression()) >+ return WTFMove(*expression); >+ return nullptr; >+ }); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ auto body = parseStatement(); >+ if (!body) >+ return Unexpected<Error>(body.error()); >+ >+ return AST::ForLoop(WTFMove(*origin), WTFMove(initialization), WTFMove(condition), WTFMove(increment), WTFMove(*body)); >+ }; >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto variableDeclarations = backtrackingScope<Expected<AST::VariableDeclarationsStatement, Error>>([&]() { >+ return parseVariableDeclarations(); >+ }); >+ if (variableDeclarations) >+ return parseRemainder(WTFMove(*variableDeclarations)); >+ >+ auto effectfulExpression = parseEffectfulExpression(); >+ if (!effectfulExpression) >+ return Unexpected<Error>(effectfulExpression.error()); >+ >+ return parseRemainder(WTFMove(*effectfulExpression)); >+} >+ >+auto Parser::parseWhileLoop() -> Expected<AST::WhileLoop, Error> { >+ auto origin = consumeType(Lexer::Token::Type::While); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto conditional = parseExpression(); >+ if (!conditional) >+ return Unexpected<Error>(conditional.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ auto body = parseStatement(); >+ if (!body) >+ return Unexpected<Error>(body.error()); >+ >+ return AST::WhileLoop(WTFMove(*origin), WTFMove(*conditional), WTFMove(*body)); >+} >+ >+auto Parser::parseDoWhileLoop() -> Expected<AST::DoWhileLoop, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Do); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto body = parseStatement(); >+ if (!body) >+ return Unexpected<Error>(body.error()); >+ >+ auto whileKeyword = consumeType(Lexer::Token::Type::While); >+ if (!whileKeyword) >+ return Unexpected<Error>(whileKeyword.error()); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto conditional = parseExpression(); >+ if (!conditional) >+ return Unexpected<Error>(conditional.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return AST::DoWhileLoop(WTFMove(*origin), WTFMove(*body), WTFMove(*conditional)); >+} >+ >+auto Parser::parseVariableDeclaration(std::unique_ptr<AST::Type>&& type) -> Expected<AST::VariableDeclaration, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto qualifiers = parseQualifiers(); >+ >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ >+ if (tryType(Lexer::Token::Type::Colon)) { >+ auto semantic = parseSemantic(); >+ if (!semantic) >+ return Unexpected<Error>(semantic.error()); >+ >+ if (tryType(Lexer::Token::Type::EqualsSign)) { >+ auto initializer = parseExpression(); >+ if (!initializer) >+ return Unexpected<Error>(initializer.error()); >+ return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), WTFMove(type), name->stringView.toString(), WTFMove(*semantic), WTFMove(*initializer)); >+ } >+ >+ return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), WTFMove(type), name->stringView.toString(), WTFMove(*semantic), nullptr); >+ } >+ >+ if (tryType(Lexer::Token::Type::EqualsSign)) { >+ auto initializer = parseExpression(); >+ if (!initializer) >+ return Unexpected<Error>(initializer.error()); >+ return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), WTFMove(type), name->stringView.toString(), std::nullopt, WTFMove(*initializer)); >+ } >+ >+ return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), WTFMove(type), name->stringView.toString(), std::nullopt, nullptr); >+} >+ >+auto Parser::parseVariableDeclarations() -> Expected<AST::VariableDeclarationsStatement, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto type = parseType(); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ auto firstVariableDeclaration = parseVariableDeclaration(std::unique_ptr<AST::Type>((*type)->clone())); >+ if (!firstVariableDeclaration) >+ return Unexpected<Error>(firstVariableDeclaration.error()); >+ >+ Vector<AST::VariableDeclaration> result; >+ result.append(WTFMove(*firstVariableDeclaration)); >+ >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto variableDeclaration = parseVariableDeclaration(std::unique_ptr<AST::Type>((*type)->clone())); >+ if (!variableDeclaration) >+ return Unexpected<Error>(variableDeclaration.error()); >+ result.append(WTFMove(*variableDeclaration)); >+ } >+ >+ return AST::VariableDeclarationsStatement(WTFMove(*origin), WTFMove(result)); >+} >+ >+auto Parser::parseStatement() -> Expected<std::unique_ptr<AST::Statement>, Error> { >+ { >+ auto block = backtrackingScope<Expected<AST::Block, Error>>([&]() { >+ return parseBlock(); >+ }); >+ if (block) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Block>(WTFMove(*block))); >+ } >+ >+ { >+ auto ifStatement = backtrackingScope<Expected<AST::IfStatement, Error>>([&]() { >+ return parseIfStatement(); >+ }); >+ if (ifStatement) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::IfStatement>(WTFMove(*ifStatement))); >+ } >+ >+ { >+ auto switchStatement = backtrackingScope<Expected<AST::SwitchStatement, Error>>([&]() { >+ return parseSwitchStatement(); >+ }); >+ if (switchStatement) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::SwitchStatement>(WTFMove(*switchStatement))); >+ } >+ >+ { >+ auto forLoop = backtrackingScope<Expected<AST::ForLoop, Error>>([&]() { >+ return parseForLoop(); >+ }); >+ if (forLoop) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::ForLoop>(WTFMove(*forLoop))); >+ } >+ >+ { >+ auto whileLoop = backtrackingScope<Expected<AST::WhileLoop, Error>>([&]() { >+ return parseWhileLoop(); >+ }); >+ if (whileLoop) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::WhileLoop>(WTFMove(*whileLoop))); >+ } >+ >+ { >+ auto doWhileLoop = backtrackingScope<Expected<AST::DoWhileLoop, Error>>([&]() -> Expected<AST::DoWhileLoop, Error> { >+ auto result = parseDoWhileLoop(); >+ if (!result) >+ return Unexpected<Error>(result.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return result; >+ }); >+ if (doWhileLoop) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::DoWhileLoop>(WTFMove(*doWhileLoop))); >+ } >+ >+ { >+ auto breakObject = backtrackingScope<Expected<AST::Break, Error>>([&]() -> Expected<AST::Break, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Break); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::Break(WTFMove(*origin)); >+ }); >+ if (breakObject) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Break>(WTFMove(*breakObject))); >+ } >+ >+ { >+ auto continueObject = backtrackingScope<Expected<AST::Continue, Error>>([&]() -> Expected<AST::Continue, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Continue); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::Continue(WTFMove(*origin)); >+ }); >+ if (continueObject) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Continue>(WTFMove(*continueObject))); >+ } >+ >+ { >+ auto fallthroughObject = backtrackingScope<Expected<AST::Fallthrough, Error>>([&]() -> Expected<AST::Fallthrough, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Fallthrough); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::Fallthrough(WTFMove(*origin)); >+ }); >+ if (fallthroughObject) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Fallthrough>(WTFMove(*fallthroughObject))); >+ } >+ >+ { >+ auto trapObject = backtrackingScope<Expected<AST::Trap, Error>>([&]() -> Expected<AST::Trap, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Trap); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::Trap(WTFMove(*origin)); >+ }); >+ if (trapObject) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Trap>(WTFMove(*trapObject))); >+ } >+ >+ { >+ auto returnObject = backtrackingScope<Expected<AST::Return, Error>>([&]() -> Expected<AST::Return, Error> { >+ auto origin = consumeType(Lexer::Token::Type::Return); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ if (auto semicolon = tryType(Lexer::Token::Type::Semicolon)) >+ return AST::Return(WTFMove(*origin), nullptr); >+ >+ auto expression = parseExpression(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return AST::Return(WTFMove(*origin), WTFMove(*expression)); >+ }); >+ if (returnObject) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::Return>(WTFMove(*returnObject))); >+ } >+ >+ { >+ auto variableDeclarations = backtrackingScope<Expected<AST::VariableDeclarationsStatement, Error>>([&]() -> Expected<AST::VariableDeclarationsStatement, Error> { >+ auto result = parseVariableDeclarations(); >+ if (!result) >+ return Unexpected<Error>(result.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return result; >+ }); >+ if (variableDeclarations) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations))); >+ } >+ >+ auto effectfulExpression = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto result = parseEffectfulExpression(); >+ if (!result) >+ return Unexpected<Error>(result.error()); >+ >+ auto semicolon = consumeType(Lexer::Token::Type::Semicolon); >+ if (!semicolon) >+ return Unexpected<Error>(semicolon.error()); >+ >+ return result; >+ }); >+ if (effectfulExpression) >+ return std::unique_ptr<AST::Statement>(std::make_unique<AST::EffectfulExpressionStatement>(WTFMove(*effectfulExpression))); >+ >+ return Unexpected<Error>(effectfulExpression.error()); >+} >+ >+auto Parser::parseEffectfulExpression() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ Vector<std::unique_ptr<AST::Expression>> expressions; >+ >+ auto first = backtrackingScope<std::unique_ptr<AST::Expression>>([&]() -> std::unique_ptr<AST::Expression> { >+ auto effectfulExpression = parseEffectfulAssignment(); >+ if (!effectfulExpression) >+ return nullptr; >+ return WTFMove(*effectfulExpression); >+ }); >+ if (!first) >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions))); >+ >+ expressions.append(WTFMove(first)); >+ >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto expression = parseEffectfulAssignment(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ expressions.append(WTFMove(*expression)); >+ } >+ >+ if (expressions.size() == 1) >+ return WTFMove(expressions[0]); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions))); >+} >+ >+auto Parser::parseEffectfulAssignment() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto assignment = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseAssignment(); >+ }); >+ if (assignment) >+ return assignment; >+ >+ assignment = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseEffectfulPrefix(); >+ }); >+ if (assignment) >+ return assignment; >+ >+ assignment = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseCallExpression(); >+ }); >+ if (assignment) >+ return assignment; >+ >+ return Unexpected<Error>(assignment.error()); >+} >+ >+auto Parser::parseEffectfulPrefix() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto prefix = consumeTypes({ Lexer::Token::Type::PlusPlus, Lexer::Token::Type::MinusMinus }); >+ if (!prefix) >+ return Unexpected<Error>(prefix.error()); >+ >+ auto previous = parsePossiblePrefix(); >+ if (!previous) >+ return Unexpected<Error>(previous.error()); >+ >+ switch (prefix->type) { >+ case Lexer::Token::Type::PlusPlus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*prefix), WTFMove(*previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*prefix), String("operator++", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->newVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ case Lexer::Token::Type::MinusMinus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*prefix), WTFMove(*previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*prefix), String("operator--", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->newVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+auto Parser::parseEffectfulSuffix() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto effectfulSuffix = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto previous = parsePossibleSuffix(); >+ if (!previous) >+ return Unexpected<Error>(previous.error()); >+ >+ auto suffix = consumeTypes({ Lexer::Token::Type::PlusPlus, Lexer::Token::Type::MinusMinus }); >+ if (!suffix) >+ return Unexpected<Error>(suffix.error()); >+ >+ switch (suffix->type) { >+ case Lexer::Token::Type::PlusPlus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*suffix), WTFMove(*previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*suffix), String("operator++", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->oldVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ case Lexer::Token::Type::MinusMinus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*suffix), WTFMove(*previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*suffix), String("operator--", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->oldVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ }); >+ if (effectfulSuffix) >+ return effectfulSuffix; >+ >+ effectfulSuffix = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseCallExpression(); >+ }); >+ if (effectfulSuffix) >+ return effectfulSuffix; >+ >+ effectfulSuffix = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ auto expression = parseExpression(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return std::unique_ptr<AST::Expression>(WTFMove(*expression)); >+ }); >+ if (effectfulSuffix) >+ return effectfulSuffix; >+ >+ return Unexpected<Error>(effectfulSuffix.error()); >+} >+ >+auto Parser::parseLimitedSuffixOperator(std::unique_ptr<AST::Expression>&& previous) -> SuffixExpression >+{ >+ auto type = consumeTypes({ Lexer::Token::Type::FullStop, Lexer::Token::Type::Arrow, Lexer::Token::Type::LeftSquareBracket }); >+ if (!type) >+ return SuffixExpression(WTFMove(previous), false); >+ >+ switch (type->type) { >+ case Lexer::Token::Type::FullStop: { >+ auto identifier = consumeType(Lexer::Token::Type::Identifier); >+ if (!identifier) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::DotExpression>(WTFMove(*type), WTFMove(previous), identifier->stringView.toString()), true); >+ } >+ case Lexer::Token::Type::Arrow: { >+ auto identifier = consumeType(Lexer::Token::Type::Identifier); >+ if (!identifier) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::DotExpression>(Lexer::Token(*type), std::make_unique<AST::DereferenceExpression>(WTFMove(*type), WTFMove(previous)), identifier->stringView.toString()), true); >+ } >+ case Lexer::Token::Type::LeftSquareBracket: { >+ auto expression = parseExpression(); >+ if (!expression) >+ return SuffixExpression(WTFMove(previous), false); >+ if (!consumeType(Lexer::Token::Type::RightSquareBracket)) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::IndexExpression>(WTFMove(*type), WTFMove(previous), WTFMove(*expression)), true); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return SuffixExpression(WTFMove(previous), false); >+ } >+} >+ >+auto Parser::parseSuffixOperator(std::unique_ptr<AST::Expression>&& previous) -> SuffixExpression >+{ >+ auto suffix = consumeTypes({ Lexer::Token::Type::FullStop, Lexer::Token::Type::Arrow, Lexer::Token::Type::LeftSquareBracket, Lexer::Token::Type::PlusPlus, Lexer::Token::Type::MinusMinus }); >+ if (!suffix) >+ return SuffixExpression(WTFMove(previous), false); >+ >+ switch (suffix->type) { >+ case Lexer::Token::Type::FullStop: { >+ auto identifier = consumeType(Lexer::Token::Type::Identifier); >+ if (!identifier) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::DotExpression>(WTFMove(*suffix), WTFMove(previous), identifier->stringView.toString()), true); >+ } >+ case Lexer::Token::Type::Arrow: { >+ auto identifier = consumeType(Lexer::Token::Type::Identifier); >+ if (!identifier) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::DotExpression>(Lexer::Token(*suffix), std::make_unique<AST::DereferenceExpression>(WTFMove(*suffix), WTFMove(previous)), identifier->stringView.toString()), true); >+ } >+ case Lexer::Token::Type::LeftSquareBracket: { >+ auto expression = parseExpression(); >+ if (!expression) >+ return SuffixExpression(WTFMove(previous), false); >+ if (!consumeType(Lexer::Token::Type::RightSquareBracket)) >+ return SuffixExpression(WTFMove(previous), false); >+ return SuffixExpression(std::make_unique<AST::IndexExpression>(WTFMove(*suffix), WTFMove(previous), WTFMove(*expression)), true); >+ } >+ case Lexer::Token::Type::PlusPlus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*suffix), WTFMove(previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*suffix), String("operator++", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->oldVariableReference()); >+ return SuffixExpression(WTFMove(result), true); >+ } >+ case Lexer::Token::Type::MinusMinus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*suffix), WTFMove(previous)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*suffix), String("operator--", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->oldVariableReference()); >+ return SuffixExpression(WTFMove(result), true); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return SuffixExpression(WTFMove(previous), false); >+ } >+} >+ >+auto Parser::parseExpression() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto first = parsePossibleTernaryConditional(); >+ if (!first) >+ return Unexpected<Error>(first.error()); >+ >+ Vector<std::unique_ptr<AST::Expression>> expressions; >+ expressions.append(WTFMove(*first)); >+ >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto expression = parsePossibleTernaryConditional(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ expressions.append(WTFMove(*expression)); >+ } >+ >+ if (expressions.size() == 1) >+ return WTFMove(expressions[0]); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions))); >+} >+ >+auto Parser::parseTernaryConditional() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto predicate = parsePossibleLogicalBinaryOperation(); >+ if (!predicate) >+ return Unexpected<Error>(predicate.error()); >+ >+ auto questionMark = consumeType(Lexer::Token::Type::QuestionMark); >+ if (!questionMark) >+ return Unexpected<Error>(questionMark.error()); >+ >+ auto bodyExpression = parseExpression(); >+ if (!bodyExpression) >+ return Unexpected<Error>(bodyExpression.error()); >+ >+ auto colon = consumeType(Lexer::Token::Type::Colon); >+ if (!colon) >+ return Unexpected<Error>(colon.error()); >+ >+ auto elseExpression = parsePossibleTernaryConditional(); >+ if (!elseExpression) >+ return Unexpected<Error>(elseExpression.error()); >+ >+ // FIXME: Cast the predicate to a bool. >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::TernaryExpression>(WTFMove(*origin), WTFMove(*predicate), WTFMove(*bodyExpression), WTFMove(*elseExpression))); >+} >+ >+auto Parser::parseAssignment() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto origin = peek(); >+ if (!origin) >+ return Unexpected<Error>(origin.error()); >+ >+ auto left = parsePossiblePrefix(); >+ if (!left) >+ return Unexpected<Error>(left.error()); >+ >+ auto assignmentOperator = consumeTypes({ >+ Lexer::Token::Type::EqualsSign, >+ Lexer::Token::Type::PlusEquals, >+ Lexer::Token::Type::MinusEquals, >+ Lexer::Token::Type::TimesEquals, >+ Lexer::Token::Type::DivideEquals, >+ Lexer::Token::Type::ModEquals, >+ Lexer::Token::Type::XorEquals, >+ Lexer::Token::Type::AndEquals, >+ Lexer::Token::Type::OrEquals, >+ Lexer::Token::Type::RightShiftEquals, >+ Lexer::Token::Type::LeftShiftEquals >+ }); >+ if (!assignmentOperator) >+ return Unexpected<Error>(assignmentOperator.error()); >+ >+ auto right = parsePossibleTernaryConditional(); >+ if (!right) >+ return Unexpected<Error>(right.error()); >+ >+ if (assignmentOperator->type == Lexer::Token::Type::EqualsSign) >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::AssignmentExpression>(WTFMove(*origin), WTFMove(*left), WTFMove(*right))); >+ >+ String name; >+ switch (assignmentOperator->type) { >+ case Lexer::Token::Type::PlusEquals: >+ name = String("operator+", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::MinusEquals: >+ name = String("operator-", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::TimesEquals: >+ name = String("operator*", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::DivideEquals: >+ name = String("operator/", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::ModEquals: >+ name = String("operator%", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::XorEquals: >+ name = String("operator^", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::AndEquals: >+ name = String("operator&", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::OrEquals: >+ name = String("operator|", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::RightShiftEquals: >+ name = String("operator>>", String::ConstructFromLiteral); >+ break; >+ case Lexer::Token::Type::LeftShiftEquals: >+ name = String("operator<<", String::ConstructFromLiteral); >+ break; >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*origin), WTFMove(*left)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ callArguments.append(WTFMove(*right)); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(WTFMove(*origin), WTFMove(name), WTFMove(callArguments))); >+ result->setResultExpression(result->newVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+} >+ >+auto Parser::parsePossibleTernaryConditional() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto ternaryExpression = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseTernaryConditional(); >+ }); >+ if (ternaryExpression) >+ return ternaryExpression; >+ >+ auto assignmentExpression = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parseAssignment(); >+ }); >+ if (assignmentExpression) >+ return assignmentExpression; >+ >+ auto binaryOperation = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() { >+ return parsePossibleLogicalBinaryOperation(); >+ }); >+ if (binaryOperation) >+ return binaryOperation; >+ >+ return Unexpected<Error>(binaryOperation.error()); >+} >+ >+auto Parser::parsePossibleLogicalBinaryOperation() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ std::unique_ptr<AST::Expression> previous; >+ auto parsedPrevious = parsePossibleRelationalBinaryOperation(); >+ if (!parsedPrevious) >+ return Unexpected<Error>(parsedPrevious.error()); >+ previous = WTFMove(*parsedPrevious); >+ >+ while (auto logicalBinaryOperation = tryTypes({ >+ Lexer::Token::Type::OrOr, >+ Lexer::Token::Type::AndAnd, >+ Lexer::Token::Type::Or, >+ Lexer::Token::Type::Xor, >+ Lexer::Token::Type::And >+ })) { >+ auto next = parsePossibleRelationalBinaryOperation(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (logicalBinaryOperation->type) { >+ case Lexer::Token::Type::OrOr: >+ previous = std::make_unique<AST::LogicalExpression>(WTFMove(*logicalBinaryOperation), AST::LogicalExpression::Type::Or, WTFMove(previous), WTFMove(*next)); >+ break; >+ case Lexer::Token::Type::AndAnd: >+ previous = std::make_unique<AST::LogicalExpression>(WTFMove(*logicalBinaryOperation), AST::LogicalExpression::Type::And, WTFMove(previous), WTFMove(*next)); >+ break; >+ case Lexer::Token::Type::Or: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*logicalBinaryOperation), String("operator|", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::Xor: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*logicalBinaryOperation), String("operator^", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::And: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*logicalBinaryOperation), String("operator&", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return WTFMove(previous); >+} >+ >+auto Parser::parsePossibleRelationalBinaryOperation() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ std::unique_ptr<AST::Expression> previous; >+ auto parsedPrevious = parsePossibleShift(); >+ if (!parsedPrevious) >+ return Unexpected<Error>(parsedPrevious.error()); >+ previous = WTFMove(*parsedPrevious); >+ >+ while (auto relationalBinaryOperation = tryTypes({ >+ Lexer::Token::Type::LessThanSign, >+ Lexer::Token::Type::GreaterThanSign, >+ Lexer::Token::Type::LessThanOrEqualTo, >+ Lexer::Token::Type::GreaterThanOrEqualTo, >+ Lexer::Token::Type::EqualComparison, >+ Lexer::Token::Type::NotEqual >+ })) { >+ auto next = parsePossibleShift(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (relationalBinaryOperation->type) { >+ case Lexer::Token::Type::LessThanSign: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*relationalBinaryOperation), String("operator<", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::GreaterThanSign: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*relationalBinaryOperation), String("operator>", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::LessThanOrEqualTo: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*relationalBinaryOperation), String("operator<=", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::GreaterThanOrEqualTo: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*relationalBinaryOperation), String("operator>=", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::EqualComparison: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*relationalBinaryOperation), String("operator==", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::NotEqual: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(Lexer::Token(*relationalBinaryOperation), String("operator==", String::ConstructFromLiteral), WTFMove(callArguments)); >+ // FIXME: Cast the argument to a bool >+ previous = std::make_unique<AST::LogicalNotExpression>(WTFMove(*relationalBinaryOperation), WTFMove(previous)); >+ break; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return previous; >+} >+ >+auto Parser::parsePossibleShift() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ std::unique_ptr<AST::Expression> previous; >+ auto parsedPrevious = parsePossibleAdd(); >+ if (!parsedPrevious) >+ return Unexpected<Error>(parsedPrevious.error()); >+ previous = WTFMove(*parsedPrevious); >+ >+ while (auto shift = tryTypes({ >+ Lexer::Token::Type::LeftShift, >+ Lexer::Token::Type::RightShift >+ })) { >+ auto next = parsePossibleAdd(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (shift->type) { >+ case Lexer::Token::Type::LeftShift: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*shift), String("operator<<", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::RightShift: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*shift), String("operator>>", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return previous; >+} >+ >+auto Parser::parsePossibleAdd() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ std::unique_ptr<AST::Expression> previous; >+ auto parsedPrevious = parsePossibleMultiply(); >+ if (!parsedPrevious) >+ return Unexpected<Error>(parsedPrevious.error()); >+ previous = WTFMove(*parsedPrevious); >+ >+ while (auto add = tryTypes({ >+ Lexer::Token::Type::Plus, >+ Lexer::Token::Type::Minus >+ })) { >+ auto next = parsePossibleMultiply(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (add->type) { >+ case Lexer::Token::Type::Plus: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*add), String("operator+", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::Minus: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*add), String("operator-", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return previous; >+} >+ >+auto Parser::parsePossibleMultiply() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ std::unique_ptr<AST::Expression> previous; >+ auto parsedPrevious = parsePossiblePrefix(); >+ if (!parsedPrevious) >+ return Unexpected<Error>(parsedPrevious.error()); >+ previous = WTFMove(*parsedPrevious); >+ >+ while (auto multiply = tryTypes({ >+ Lexer::Token::Type::Star, >+ Lexer::Token::Type::Divide, >+ Lexer::Token::Type::Mod >+ })) { >+ auto next = parsePossiblePrefix(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (multiply->type) { >+ case Lexer::Token::Type::Star: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*multiply), String("operator*", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::Divide: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*multiply), String("operator/", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ case Lexer::Token::Type::Mod: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(previous)); >+ callArguments.append(WTFMove(*next)); >+ previous = std::make_unique<AST::CallExpression>(WTFMove(*multiply), String("operator%", String::ConstructFromLiteral), WTFMove(callArguments)); >+ break; >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return previous; >+} >+ >+auto Parser::parsePossiblePrefix() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ if (auto prefix = tryTypes({ >+ Lexer::Token::Type::PlusPlus, >+ Lexer::Token::Type::MinusMinus, >+ Lexer::Token::Type::Plus, >+ Lexer::Token::Type::Minus, >+ Lexer::Token::Type::Tilde, >+ Lexer::Token::Type::ExclamationPoint, >+ Lexer::Token::Type::And, >+ Lexer::Token::Type::At, >+ Lexer::Token::Type::Star >+ })) { >+ auto next = parsePossiblePrefix(); >+ if (!next) >+ return Unexpected<Error>(next.error()); >+ >+ switch (prefix->type) { >+ case Lexer::Token::Type::PlusPlus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*prefix), WTFMove(*next)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(Lexer::Token(*prefix), String("operator++", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->newVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ case Lexer::Token::Type::MinusMinus: { >+ auto result = std::make_unique<AST::ReadModifyWriteExpression>(Lexer::Token(*prefix), WTFMove(*next)); >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(result->oldVariableReference()); >+ result->setNewValueExpression(std::make_unique<AST::CallExpression>(Lexer::Token(*prefix), String("operator--", String::ConstructFromLiteral), WTFMove(callArguments))); >+ result->setResultExpression(result->newVariableReference()); >+ return std::unique_ptr<AST::Expression>(WTFMove(result)); >+ } >+ case Lexer::Token::Type::Plus: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(*next)); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CallExpression>(Lexer::Token(*prefix), String("operator+", String::ConstructFromLiteral), WTFMove(callArguments))); >+ } >+ case Lexer::Token::Type::Minus: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(*next)); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CallExpression>(Lexer::Token(*prefix), String("operator-", String::ConstructFromLiteral), WTFMove(callArguments))); >+ } >+ case Lexer::Token::Type::Tilde: { >+ Vector<std::unique_ptr<AST::Expression>> callArguments; >+ callArguments.append(WTFMove(*next)); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CallExpression>(Lexer::Token(*prefix), String("operator~", String::ConstructFromLiteral), WTFMove(callArguments))); >+ } >+ case Lexer::Token::Type::ExclamationPoint: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::LogicalNotExpression>(Lexer::Token(*prefix), WTFMove(*next))); >+ case Lexer::Token::Type::And: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::MakePointerExpression>(Lexer::Token(*prefix), WTFMove(*next))); >+ case Lexer::Token::Type::At: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::MakeArrayReferenceExpression>(Lexer::Token(*prefix), WTFMove(*next))); >+ case Lexer::Token::Type::Star: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::DereferenceExpression>(Lexer::Token(*prefix), WTFMove(*next))); >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+ } >+ >+ return parsePossibleSuffix(); >+} >+ >+auto Parser::parsePossibleSuffix() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto suffix = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto expression = parseCallExpression(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ >+ while (true) { >+ auto result = backtrackingScope<SuffixExpression>([&]() -> SuffixExpression { >+ return parseLimitedSuffixOperator(WTFMove(*expression)); >+ }); >+ expression = WTFMove(result.result); >+ if (!result) >+ break; >+ } >+ return expression; >+ }); >+ if (suffix) >+ return suffix; >+ >+ suffix = backtrackingScope<Expected<std::unique_ptr<AST::Expression>, Error>>([&]() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto expression = parseTerm(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ >+ while (true) { >+ auto result = backtrackingScope<SuffixExpression>([&]() -> SuffixExpression { >+ return parseSuffixOperator(WTFMove(*expression)); >+ }); >+ expression = WTFMove(result.result); >+ if (!result) >+ break; >+ } >+ return expression; >+ }); >+ if (suffix) >+ return suffix; >+ >+ return Unexpected<Error>(suffix.error()); >+} >+ >+auto Parser::parseCallExpression() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto name = consumeType(Lexer::Token::Type::Identifier); >+ if (!name) >+ return Unexpected<Error>(name.error()); >+ auto callName = name->stringView.toString(); >+ >+ auto leftParenthesis = consumeType(Lexer::Token::Type::LeftParenthesis); >+ if (!leftParenthesis) >+ return Unexpected<Error>(leftParenthesis.error()); >+ >+ Vector<std::unique_ptr<AST::Expression>> arguments; >+ if (tryType(Lexer::Token::Type::RightParenthesis)) >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CallExpression>(WTFMove(*name), WTFMove(callName), WTFMove(arguments))); >+ >+ auto firstArgument = parsePossibleTernaryConditional(); >+ if (!firstArgument) >+ return Unexpected<Error>(firstArgument.error()); >+ arguments.append(WTFMove(*firstArgument)); >+ while (tryType(Lexer::Token::Type::Comma)) { >+ auto argument = parsePossibleTernaryConditional(); >+ if (!argument) >+ return Unexpected<Error>(argument.error()); >+ arguments.append(WTFMove(*argument)); >+ } >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::CallExpression>(WTFMove(*name), WTFMove(callName), WTFMove(arguments))); >+} >+ >+auto Parser::parseTerm() -> Expected<std::unique_ptr<AST::Expression>, Error> { >+ auto type = consumeTypes({ >+ Lexer::Token::Type::IntLiteral, >+ Lexer::Token::Type::UintLiteral, >+ Lexer::Token::Type::FloatLiteral, >+ Lexer::Token::Type::Null, >+ Lexer::Token::Type::True, >+ Lexer::Token::Type::False, >+ Lexer::Token::Type::Identifier, >+ Lexer::Token::Type::LeftParenthesis >+ }); >+ if (!type) >+ return Unexpected<Error>(type.error()); >+ >+ switch (type->type) { >+ case Lexer::Token::Type::IntLiteral: { >+ auto value = intLiteralToInt(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::IntegerLiteral>(WTFMove(*type), *value)); >+ } >+ case Lexer::Token::Type::UintLiteral: { >+ auto value = uintLiteralToUint(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::UnsignedIntegerLiteral>(WTFMove(*type), *value)); >+ } >+ case Lexer::Token::Type::FloatLiteral: { >+ auto value = floatLiteralToFloat(type->stringView); >+ if (!value) >+ return Unexpected<Error>(value.error()); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::FloatLiteral>(WTFMove(*type), *value)); >+ } >+ case Lexer::Token::Type::Null: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::NullLiteral>(WTFMove(*type))); >+ case Lexer::Token::Type::True: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::BooleanLiteral>(WTFMove(*type), true)); >+ case Lexer::Token::Type::False: >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::BooleanLiteral>(WTFMove(*type), false)); >+ case Lexer::Token::Type::Identifier: { >+ auto name = type->stringView.toString(); >+ return std::unique_ptr<AST::Expression>(std::make_unique<AST::VariableReference>(WTFMove(*type), WTFMove(name))); >+ } >+ case Lexer::Token::Type::LeftParenthesis: { >+ auto expression = parseExpression(); >+ if (!expression) >+ return Unexpected<Error>(expression.error()); >+ >+ auto rightParenthesis = consumeType(Lexer::Token::Type::RightParenthesis); >+ if (!rightParenthesis) >+ return Unexpected<Error>(rightParenthesis.error()); >+ >+ return std::unique_ptr<AST::Expression>(WTFMove(*expression)); >+ } >+ default: >+ ASSERT_NOT_REACHED(); >+ return Unexpected<Error>(Error(String("Something really bad happened", String::ConstructFromLiteral))); >+ } >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h >new file mode 100644 >index 0000000000000000000000000000000000000000..0513ea4ac030a00cbbc2544f3768aa954fcbe5a5 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h >@@ -0,0 +1,194 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTBlock.h" >+#include "WHLSLASTCommaExpression.h" >+#include "WHLSLASTConstantExpression.h" >+#include "WHLSLASTDoWhileLoop.h" >+#include "WHLSLASTExpression.h" >+#include "WHLSLASTForLoop.h" >+#include "WHLSLASTFunctionAttribute.h" >+#include "WHLSLASTFunctionDeclaration.h" >+#include "WHLSLASTFunctionDefinition.h" >+#include "WHLSLASTIfStatement.h" >+#include "WHLSLASTNativeTypeDeclaration.h" >+#include "WHLSLASTParameter.h" >+#include "WHLSLASTSemantic.h" >+#include "WHLSLASTStatement.h" >+#include "WHLSLASTStructureDefinition.h" >+#include "WHLSLASTStructureElement.h" >+#include "WHLSLASTSwitchCase.h" >+#include "WHLSLASTSwitchStatement.h" >+#include "WHLSLASTTypeArgument.h" >+#include "WHLSLASTTypeDefinition.h" >+#include "WHLSLASTVariableDeclaration.h" >+#include "WHLSLASTVariableDeclarationsStatement.h" >+#include "WHLSLASTWhileLoop.h" >+#include "WHLSLLexer.h" >+#include "WHLSLProgram.h" >+#include <wtf/Expected.h> >+#include <wtf/Optional.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Parser { >+public: >+ enum class Mode { >+ StandardLibrary, >+ User >+ }; >+ >+ struct Error { >+ Error(String&& error) >+ : error(WTFMove(error)) >+ { >+ } >+ >+ String error; >+ }; >+ >+ Parser(); >+ >+ std::optional<Error> parse(Program&, StringView, Mode); >+ >+private: >+ template<typename T> T backtrackingScope(std::function<T()> callback) >+ { >+ auto state = m_lexer.state(); >+ auto result = callback(); >+ if (result) >+ return result; >+ m_lexer.setState(WTFMove(state)); >+ return result; >+ } >+ >+ Unexpected<Error> fail(const String& message); >+ Expected<Lexer::Token, Error> peek(); >+ std::optional<Lexer::Token> tryType(Lexer::Token::Type); >+ std::optional<Lexer::Token> tryTypes(Vector<Lexer::Token::Type>); >+ Expected<Lexer::Token, Error> consumeType(Lexer::Token::Type); >+ Expected<Lexer::Token, Error> consumeTypes(Vector<Lexer::Token::Type>); >+ >+ Expected<Variant<int, unsigned>, Error> consumeIntegralLiteral(); >+ Expected<unsigned, Error> consumeNonNegativeIntegralLiteral(); >+ Expected<AST::ConstantExpression, Error> parseConstantExpression(); >+ Expected<AST::TypeArgument, Error> parseTypeArgument(); >+ Expected<AST::TypeArguments, Error> parseTypeArguments(); >+ struct TypeSuffixAbbreviated { >+ Lexer::Token token; >+ std::optional<unsigned> numElements; >+ }; >+ Expected<TypeSuffixAbbreviated, Error> parseTypeSuffixAbbreviated(); >+ struct TypeSuffixNonAbbreviated { >+ Lexer::Token token; >+ std::optional<Lexer::Token> addressSpace; >+ std::optional<unsigned> numElements; >+ }; >+ Expected<TypeSuffixNonAbbreviated, Error> parseTypeSuffixNonAbbreviated(); >+ Expected<std::unique_ptr<AST::Type>, Error> parseAddressSpaceType(); >+ Expected<std::unique_ptr<AST::Type>, Error> parseNonAddressSpaceType(); >+ Expected<std::unique_ptr<AST::Type>, Error> parseType(); >+ Expected<AST::TypeDefinition, Error> parseTypeDefinition(); >+ Expected<AST::BuiltInSemantic, Error> parseBuiltInSemantic(); >+ Expected<AST::ResourceSemantic, Error> parseResourceSemantic(); >+ Expected<AST::SpecializationConstantSemantic, Error> parseSpecializationConstantSemantic(); >+ Expected<AST::StageInOutSemantic, Error> parseStageInOutSemantic(); >+ Expected<AST::Semantic, Error> parseSemantic(); >+ AST::Qualifiers parseQualifiers(); >+ Expected<AST::StructureElement, Error> parseStructureElement(); >+ Expected<AST::StructureDefinition, Error> parseStructureDefinition(); >+ Expected<AST::EnumerationDefinition, Error> parseEnumerationDefinition(); >+ Expected<AST::EnumerationMember, Error> parseEnumerationMember(); >+ Expected<AST::NativeTypeDeclaration, Error> parseNativeTypeDeclaration(); >+ Expected<AST::NumThreadsFunctionAttribute, Error> parseNumThreadsFunctionAttribute(); >+ Expected<AST::AttributeBlock, Error> parseAttributeBlock(); >+ Expected<AST::Parameter, Error> parseParameter(); >+ Expected<AST::Parameters, Error> parseParameters(); >+ Expected<AST::FunctionDeclaration, Error> parseEntryPointFunctionDeclaration(); >+ Expected<AST::FunctionDeclaration, Error> parseRegularFunctionDeclaration(); >+ Expected<AST::FunctionDeclaration, Error> parseOperatorFunctionDeclaration(); >+ Expected<AST::FunctionDeclaration, Error> parseFunctionDeclaration(); >+ Expected<AST::FunctionDefinition, Error> parseFunctionDefinition(); >+ Expected<AST::NativeFunctionDeclaration, Error> parseNativeFunctionDeclaration(); >+ >+ Expected<AST::Block, Error> parseBlock(); >+ AST::Block parseBlockBody(Lexer::Token&& origin); >+ Expected<AST::IfStatement, Error> parseIfStatement(); >+ Expected<AST::SwitchStatement, Error> parseSwitchStatement(); >+ Expected<AST::SwitchCase, Error> parseSwitchCase(); >+ Expected<AST::ForLoop, Error> parseForLoop(); >+ Expected<AST::WhileLoop, Error> parseWhileLoop(); >+ Expected<AST::DoWhileLoop, Error> parseDoWhileLoop(); >+ Expected<AST::VariableDeclaration, Error> parseVariableDeclaration(std::unique_ptr<AST::Type>&&); >+ Expected<AST::VariableDeclarationsStatement, Error> parseVariableDeclarations(); >+ Expected<std::unique_ptr<AST::Statement>, Error> parseStatement(); >+ >+ Expected<std::unique_ptr<AST::Expression>, Error> parseEffectfulExpression(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseEffectfulAssignment(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseEffectfulPrefix(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseEffectfulSuffix(); >+ struct SuffixExpression { >+ SuffixExpression(std::unique_ptr<AST::Expression>&& result, bool success) >+ : result(WTFMove(result)) >+ , success(success) >+ { >+ } >+ >+ std::unique_ptr<AST::Expression> result; >+ bool success; >+ operator bool() const { return success; } >+ }; >+ SuffixExpression parseLimitedSuffixOperator(std::unique_ptr<AST::Expression>&&); >+ SuffixExpression parseSuffixOperator(std::unique_ptr<AST::Expression>&&); >+ >+ Expected<std::unique_ptr<AST::Expression>, Error> parseExpression(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseTernaryConditional(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseAssignment(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleTernaryConditional(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleLogicalBinaryOperation(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleRelationalBinaryOperation(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleShift(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleAdd(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleMultiply(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossiblePrefix(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parsePossibleSuffix(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseCallExpression(); >+ Expected<std::unique_ptr<AST::Expression>, Error> parseTerm(); >+ >+ Lexer m_lexer; >+ Mode m_mode; >+}; >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >new file mode 100644 >index 0000000000000000000000000000000000000000..65e613a9fb354277b78b355e668df63a4fc3317d >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >@@ -0,0 +1,85 @@ >+/* >+ * Copyright (C) 2018 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 "WHLSLASTEnumerationDefinition.h" >+#include "WHLSLASTFunctionDefinition.h" >+#include "WHLSLASTNativeFunctionDeclaration.h" >+#include "WHLSLASTNativeTypeDeclaration.h" >+#include "WHLSLASTStructureDefinition.h" >+#include "WHLSLASTTypeDefinition.h" >+#include <wtf/Vector.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program { >+public: >+ Program() = default; >+ Program(Program&&) = default; >+ >+ void append(AST::TypeDefinition&& typeDefinition) >+ { >+ m_typeDefinitions.append(WTFMove(typeDefinition)); >+ } >+ void append(AST::StructureDefinition&& structureDefinition) >+ { >+ m_structureDefinitions.append(WTFMove(structureDefinition)); >+ } >+ void append(AST::EnumerationDefinition&& enumerationDefinition) >+ { >+ m_enumerationDefinitions.append(WTFMove(enumerationDefinition)); >+ } >+ void append(AST::FunctionDefinition&& functionDefinition) >+ { >+ m_functionDefinitions.append(WTFMove(functionDefinition)); >+ } >+ void append(AST::NativeFunctionDeclaration&& nativeFunctionDeclaration) >+ { >+ m_nativeFunctionDeclarations.append(WTFMove(nativeFunctionDeclaration)); >+ } >+ void append(AST::NativeTypeDeclaration&& nativeTypeDeclaration) >+ { >+ m_nativeTypeDeclarations.append(WTFMove(nativeTypeDeclaration)); >+ } >+ >+private: >+ Vector<AST::TypeDefinition> m_typeDefinitions; >+ Vector<AST::StructureDefinition> m_structureDefinitions; >+ Vector<AST::EnumerationDefinition> m_enumerationDefinitions; >+ Vector<AST::FunctionDefinition> m_functionDefinitions; >+ Vector<AST::NativeFunctionDeclaration> m_nativeFunctionDeclarations; >+ Vector<AST::NativeTypeDeclaration> m_nativeTypeDeclarations; >+}; >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..570747b23b42e9fec12965c7786481490f7ea678 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt >@@ -0,0 +1,471 @@ >+// https://github.com/gpuweb/WHLSL/blob/9528f19aaa71fd5c3c706d2873f4b8c8cce857b5/Spec/source/Generate_Standard_Library.js >+// This was autogenerated from Generate_Standard_Library.js! Do not edit!! >+ >+native typedef void; >+native typedef bool; >+native typedef uchar; >+native typedef ushort; >+native typedef uint; >+native typedef char; >+native typedef short; >+native typedef int; >+native typedef half; >+native typedef float; >+native typedef atomic_int; >+native typedef atomic_uint; >+native typedef vector<bool, 2>; >+typedef bool2 = vector<bool, 2>; >+native typedef vector<bool, 3>; >+typedef bool3 = vector<bool, 3>; >+native typedef vector<bool, 4>; >+typedef bool4 = vector<bool, 4>; >+native typedef vector<uchar, 2>; >+typedef uchar2 = vector<uchar, 2>; >+native typedef vector<uchar, 3>; >+typedef uchar3 = vector<uchar, 3>; >+native typedef vector<uchar, 4>; >+typedef uchar4 = vector<uchar, 4>; >+native typedef vector<ushort, 2>; >+typedef ushort2 = vector<ushort, 2>; >+native typedef vector<ushort, 3>; >+typedef ushort3 = vector<ushort, 3>; >+native typedef vector<ushort, 4>; >+typedef ushort4 = vector<ushort, 4>; >+native typedef vector<uint, 2>; >+typedef uint2 = vector<uint, 2>; >+native typedef vector<uint, 3>; >+typedef uint3 = vector<uint, 3>; >+native typedef vector<uint, 4>; >+typedef uint4 = vector<uint, 4>; >+native typedef vector<char, 2>; >+typedef char2 = vector<char, 2>; >+native typedef vector<char, 3>; >+typedef char3 = vector<char, 3>; >+native typedef vector<char, 4>; >+typedef char4 = vector<char, 4>; >+native typedef vector<short, 2>; >+typedef short2 = vector<short, 2>; >+native typedef vector<short, 3>; >+typedef short3 = vector<short, 3>; >+native typedef vector<short, 4>; >+typedef short4 = vector<short, 4>; >+native typedef vector<int, 2>; >+typedef int2 = vector<int, 2>; >+native typedef vector<int, 3>; >+typedef int3 = vector<int, 3>; >+native typedef vector<int, 4>; >+typedef int4 = vector<int, 4>; >+native typedef vector<half, 2>; >+typedef half2 = vector<half, 2>; >+native typedef vector<half, 3>; >+typedef half3 = vector<half, 3>; >+native typedef vector<half, 4>; >+typedef half4 = vector<half, 4>; >+native typedef vector<float, 2>; >+typedef float2 = vector<float, 2>; >+native typedef vector<float, 3>; >+typedef float3 = vector<float, 3>; >+native typedef vector<float, 4>; >+typedef float4 = vector<float, 4>; >+ >+native typedef matrix<half, 2, 2>; >+typedef half2x2 = matrix<half, 2, 2>; >+native typedef matrix<half, 2, 3>; >+typedef half2x3 = matrix<half, 2, 3>; >+native typedef matrix<half, 2, 4>; >+typedef half2x4 = matrix<half, 2, 4>; >+native typedef matrix<half, 3, 2>; >+typedef half3x2 = matrix<half, 3, 2>; >+native typedef matrix<half, 3, 3>; >+typedef half3x3 = matrix<half, 3, 3>; >+native typedef matrix<half, 3, 4>; >+typedef half3x4 = matrix<half, 3, 4>; >+native typedef matrix<half, 4, 2>; >+typedef half4x2 = matrix<half, 4, 2>; >+native typedef matrix<half, 4, 3>; >+typedef half4x3 = matrix<half, 4, 3>; >+native typedef matrix<half, 4, 4>; >+typedef half4x4 = matrix<half, 4, 4>; >+native typedef matrix<float, 2, 2>; >+typedef float2x2 = matrix<float, 2, 2>; >+native typedef matrix<float, 2, 3>; >+typedef float2x3 = matrix<float, 2, 3>; >+native typedef matrix<float, 2, 4>; >+typedef float2x4 = matrix<float, 2, 4>; >+native typedef matrix<float, 3, 2>; >+typedef float3x2 = matrix<float, 3, 2>; >+native typedef matrix<float, 3, 3>; >+typedef float3x3 = matrix<float, 3, 3>; >+native typedef matrix<float, 3, 4>; >+typedef float3x4 = matrix<float, 3, 4>; >+native typedef matrix<float, 4, 2>; >+typedef float4x2 = matrix<float, 4, 2>; >+native typedef matrix<float, 4, 3>; >+typedef float4x3 = matrix<float, 4, 3>; >+native typedef matrix<float, 4, 4>; >+typedef float4x4 = matrix<float, 4, 4>; >+native typedef sampler; >+native typedef Texture1D<uchar>; >+native typedef Texture1D<uchar2>; >+native typedef Texture1D<uchar3>; >+native typedef Texture1D<uchar4>; >+native typedef Texture1D<ushort>; >+native typedef Texture1D<ushort2>; >+native typedef Texture1D<ushort3>; >+native typedef Texture1D<ushort4>; >+native typedef Texture1D<uint>; >+native typedef Texture1D<uint2>; >+native typedef Texture1D<uint3>; >+native typedef Texture1D<uint4>; >+native typedef Texture1D<char>; >+native typedef Texture1D<char2>; >+native typedef Texture1D<char3>; >+native typedef Texture1D<char4>; >+native typedef Texture1D<short>; >+native typedef Texture1D<short2>; >+native typedef Texture1D<short3>; >+native typedef Texture1D<short4>; >+native typedef Texture1D<int>; >+native typedef Texture1D<int2>; >+native typedef Texture1D<int3>; >+native typedef Texture1D<int4>; >+native typedef Texture1D<half>; >+native typedef Texture1D<half2>; >+native typedef Texture1D<half3>; >+native typedef Texture1D<half4>; >+native typedef Texture1D<float>; >+native typedef Texture1D<float2>; >+native typedef Texture1D<float3>; >+native typedef Texture1D<float4>; >+native typedef RWTexture1D<uchar>; >+native typedef RWTexture1D<uchar2>; >+native typedef RWTexture1D<uchar3>; >+native typedef RWTexture1D<uchar4>; >+native typedef RWTexture1D<ushort>; >+native typedef RWTexture1D<ushort2>; >+native typedef RWTexture1D<ushort3>; >+native typedef RWTexture1D<ushort4>; >+native typedef RWTexture1D<uint>; >+native typedef RWTexture1D<uint2>; >+native typedef RWTexture1D<uint3>; >+native typedef RWTexture1D<uint4>; >+native typedef RWTexture1D<char>; >+native typedef RWTexture1D<char2>; >+native typedef RWTexture1D<char3>; >+native typedef RWTexture1D<char4>; >+native typedef RWTexture1D<short>; >+native typedef RWTexture1D<short2>; >+native typedef RWTexture1D<short3>; >+native typedef RWTexture1D<short4>; >+native typedef RWTexture1D<int>; >+native typedef RWTexture1D<int2>; >+native typedef RWTexture1D<int3>; >+native typedef RWTexture1D<int4>; >+native typedef RWTexture1D<half>; >+native typedef RWTexture1D<half2>; >+native typedef RWTexture1D<half3>; >+native typedef RWTexture1D<half4>; >+native typedef RWTexture1D<float>; >+native typedef RWTexture1D<float2>; >+native typedef RWTexture1D<float3>; >+native typedef RWTexture1D<float4>; >+native typedef Texture1DArray<uchar>; >+native typedef Texture1DArray<uchar2>; >+native typedef Texture1DArray<uchar3>; >+native typedef Texture1DArray<uchar4>; >+native typedef Texture1DArray<ushort>; >+native typedef Texture1DArray<ushort2>; >+native typedef Texture1DArray<ushort3>; >+native typedef Texture1DArray<ushort4>; >+native typedef Texture1DArray<uint>; >+native typedef Texture1DArray<uint2>; >+native typedef Texture1DArray<uint3>; >+native typedef Texture1DArray<uint4>; >+native typedef Texture1DArray<char>; >+native typedef Texture1DArray<char2>; >+native typedef Texture1DArray<char3>; >+native typedef Texture1DArray<char4>; >+native typedef Texture1DArray<short>; >+native typedef Texture1DArray<short2>; >+native typedef Texture1DArray<short3>; >+native typedef Texture1DArray<short4>; >+native typedef Texture1DArray<int>; >+native typedef Texture1DArray<int2>; >+native typedef Texture1DArray<int3>; >+native typedef Texture1DArray<int4>; >+native typedef Texture1DArray<half>; >+native typedef Texture1DArray<half2>; >+native typedef Texture1DArray<half3>; >+native typedef Texture1DArray<half4>; >+native typedef Texture1DArray<float>; >+native typedef Texture1DArray<float2>; >+native typedef Texture1DArray<float3>; >+native typedef Texture1DArray<float4>; >+native typedef RWTexture1DArray<uchar>; >+native typedef RWTexture1DArray<uchar2>; >+native typedef RWTexture1DArray<uchar3>; >+native typedef RWTexture1DArray<uchar4>; >+native typedef RWTexture1DArray<ushort>; >+native typedef RWTexture1DArray<ushort2>; >+native typedef RWTexture1DArray<ushort3>; >+native typedef RWTexture1DArray<ushort4>; >+native typedef RWTexture1DArray<uint>; >+native typedef RWTexture1DArray<uint2>; >+native typedef RWTexture1DArray<uint3>; >+native typedef RWTexture1DArray<uint4>; >+native typedef RWTexture1DArray<char>; >+native typedef RWTexture1DArray<char2>; >+native typedef RWTexture1DArray<char3>; >+native typedef RWTexture1DArray<char4>; >+native typedef RWTexture1DArray<short>; >+native typedef RWTexture1DArray<short2>; >+native typedef RWTexture1DArray<short3>; >+native typedef RWTexture1DArray<short4>; >+native typedef RWTexture1DArray<int>; >+native typedef RWTexture1DArray<int2>; >+native typedef RWTexture1DArray<int3>; >+native typedef RWTexture1DArray<int4>; >+native typedef RWTexture1DArray<half>; >+native typedef RWTexture1DArray<half2>; >+native typedef RWTexture1DArray<half3>; >+native typedef RWTexture1DArray<half4>; >+native typedef RWTexture1DArray<float>; >+native typedef RWTexture1DArray<float2>; >+native typedef RWTexture1DArray<float3>; >+native typedef RWTexture1DArray<float4>; >+native typedef Texture2D<uchar>; >+native typedef Texture2D<uchar2>; >+native typedef Texture2D<uchar3>; >+native typedef Texture2D<uchar4>; >+native typedef Texture2D<ushort>; >+native typedef Texture2D<ushort2>; >+native typedef Texture2D<ushort3>; >+native typedef Texture2D<ushort4>; >+native typedef Texture2D<uint>; >+native typedef Texture2D<uint2>; >+native typedef Texture2D<uint3>; >+native typedef Texture2D<uint4>; >+native typedef Texture2D<char>; >+native typedef Texture2D<char2>; >+native typedef Texture2D<char3>; >+native typedef Texture2D<char4>; >+native typedef Texture2D<short>; >+native typedef Texture2D<short2>; >+native typedef Texture2D<short3>; >+native typedef Texture2D<short4>; >+native typedef Texture2D<int>; >+native typedef Texture2D<int2>; >+native typedef Texture2D<int3>; >+native typedef Texture2D<int4>; >+native typedef Texture2D<half>; >+native typedef Texture2D<half2>; >+native typedef Texture2D<half3>; >+native typedef Texture2D<half4>; >+native typedef Texture2D<float>; >+native typedef Texture2D<float2>; >+native typedef Texture2D<float3>; >+native typedef Texture2D<float4>; >+native typedef RWTexture2D<uchar>; >+native typedef RWTexture2D<uchar2>; >+native typedef RWTexture2D<uchar3>; >+native typedef RWTexture2D<uchar4>; >+native typedef RWTexture2D<ushort>; >+native typedef RWTexture2D<ushort2>; >+native typedef RWTexture2D<ushort3>; >+native typedef RWTexture2D<ushort4>; >+native typedef RWTexture2D<uint>; >+native typedef RWTexture2D<uint2>; >+native typedef RWTexture2D<uint3>; >+native typedef RWTexture2D<uint4>; >+native typedef RWTexture2D<char>; >+native typedef RWTexture2D<char2>; >+native typedef RWTexture2D<char3>; >+native typedef RWTexture2D<char4>; >+native typedef RWTexture2D<short>; >+native typedef RWTexture2D<short2>; >+native typedef RWTexture2D<short3>; >+native typedef RWTexture2D<short4>; >+native typedef RWTexture2D<int>; >+native typedef RWTexture2D<int2>; >+native typedef RWTexture2D<int3>; >+native typedef RWTexture2D<int4>; >+native typedef RWTexture2D<half>; >+native typedef RWTexture2D<half2>; >+native typedef RWTexture2D<half3>; >+native typedef RWTexture2D<half4>; >+native typedef RWTexture2D<float>; >+native typedef RWTexture2D<float2>; >+native typedef RWTexture2D<float3>; >+native typedef RWTexture2D<float4>; >+native typedef Texture2DArray<uchar>; >+native typedef Texture2DArray<uchar2>; >+native typedef Texture2DArray<uchar3>; >+native typedef Texture2DArray<uchar4>; >+native typedef Texture2DArray<ushort>; >+native typedef Texture2DArray<ushort2>; >+native typedef Texture2DArray<ushort3>; >+native typedef Texture2DArray<ushort4>; >+native typedef Texture2DArray<uint>; >+native typedef Texture2DArray<uint2>; >+native typedef Texture2DArray<uint3>; >+native typedef Texture2DArray<uint4>; >+native typedef Texture2DArray<char>; >+native typedef Texture2DArray<char2>; >+native typedef Texture2DArray<char3>; >+native typedef Texture2DArray<char4>; >+native typedef Texture2DArray<short>; >+native typedef Texture2DArray<short2>; >+native typedef Texture2DArray<short3>; >+native typedef Texture2DArray<short4>; >+native typedef Texture2DArray<int>; >+native typedef Texture2DArray<int2>; >+native typedef Texture2DArray<int3>; >+native typedef Texture2DArray<int4>; >+native typedef Texture2DArray<half>; >+native typedef Texture2DArray<half2>; >+native typedef Texture2DArray<half3>; >+native typedef Texture2DArray<half4>; >+native typedef Texture2DArray<float>; >+native typedef Texture2DArray<float2>; >+native typedef Texture2DArray<float3>; >+native typedef Texture2DArray<float4>; >+native typedef RWTexture2DArray<uchar>; >+native typedef RWTexture2DArray<uchar2>; >+native typedef RWTexture2DArray<uchar3>; >+native typedef RWTexture2DArray<uchar4>; >+native typedef RWTexture2DArray<ushort>; >+native typedef RWTexture2DArray<ushort2>; >+native typedef RWTexture2DArray<ushort3>; >+native typedef RWTexture2DArray<ushort4>; >+native typedef RWTexture2DArray<uint>; >+native typedef RWTexture2DArray<uint2>; >+native typedef RWTexture2DArray<uint3>; >+native typedef RWTexture2DArray<uint4>; >+native typedef RWTexture2DArray<char>; >+native typedef RWTexture2DArray<char2>; >+native typedef RWTexture2DArray<char3>; >+native typedef RWTexture2DArray<char4>; >+native typedef RWTexture2DArray<short>; >+native typedef RWTexture2DArray<short2>; >+native typedef RWTexture2DArray<short3>; >+native typedef RWTexture2DArray<short4>; >+native typedef RWTexture2DArray<int>; >+native typedef RWTexture2DArray<int2>; >+native typedef RWTexture2DArray<int3>; >+native typedef RWTexture2DArray<int4>; >+native typedef RWTexture2DArray<half>; >+native typedef RWTexture2DArray<half2>; >+native typedef RWTexture2DArray<half3>; >+native typedef RWTexture2DArray<half4>; >+native typedef RWTexture2DArray<float>; >+native typedef RWTexture2DArray<float2>; >+native typedef RWTexture2DArray<float3>; >+native typedef RWTexture2DArray<float4>; >+native typedef Texture3D<uchar>; >+native typedef Texture3D<uchar2>; >+native typedef Texture3D<uchar3>; >+native typedef Texture3D<uchar4>; >+native typedef Texture3D<ushort>; >+native typedef Texture3D<ushort2>; >+native typedef Texture3D<ushort3>; >+native typedef Texture3D<ushort4>; >+native typedef Texture3D<uint>; >+native typedef Texture3D<uint2>; >+native typedef Texture3D<uint3>; >+native typedef Texture3D<uint4>; >+native typedef Texture3D<char>; >+native typedef Texture3D<char2>; >+native typedef Texture3D<char3>; >+native typedef Texture3D<char4>; >+native typedef Texture3D<short>; >+native typedef Texture3D<short2>; >+native typedef Texture3D<short3>; >+native typedef Texture3D<short4>; >+native typedef Texture3D<int>; >+native typedef Texture3D<int2>; >+native typedef Texture3D<int3>; >+native typedef Texture3D<int4>; >+native typedef Texture3D<half>; >+native typedef Texture3D<half2>; >+native typedef Texture3D<half3>; >+native typedef Texture3D<half4>; >+native typedef Texture3D<float>; >+native typedef Texture3D<float2>; >+native typedef Texture3D<float3>; >+native typedef Texture3D<float4>; >+native typedef RWTexture3D<uchar>; >+native typedef RWTexture3D<uchar2>; >+native typedef RWTexture3D<uchar3>; >+native typedef RWTexture3D<uchar4>; >+native typedef RWTexture3D<ushort>; >+native typedef RWTexture3D<ushort2>; >+native typedef RWTexture3D<ushort3>; >+native typedef RWTexture3D<ushort4>; >+native typedef RWTexture3D<uint>; >+native typedef RWTexture3D<uint2>; >+native typedef RWTexture3D<uint3>; >+native typedef RWTexture3D<uint4>; >+native typedef RWTexture3D<char>; >+native typedef RWTexture3D<char2>; >+native typedef RWTexture3D<char3>; >+native typedef RWTexture3D<char4>; >+native typedef RWTexture3D<short>; >+native typedef RWTexture3D<short2>; >+native typedef RWTexture3D<short3>; >+native typedef RWTexture3D<short4>; >+native typedef RWTexture3D<int>; >+native typedef RWTexture3D<int2>; >+native typedef RWTexture3D<int3>; >+native typedef RWTexture3D<int4>; >+native typedef RWTexture3D<half>; >+native typedef RWTexture3D<half2>; >+native typedef RWTexture3D<half3>; >+native typedef RWTexture3D<half4>; >+native typedef RWTexture3D<float>; >+native typedef RWTexture3D<float2>; >+native typedef RWTexture3D<float3>; >+native typedef RWTexture3D<float4>; >+native typedef TextureCube<uchar>; >+native typedef TextureCube<uchar2>; >+native typedef TextureCube<uchar3>; >+native typedef TextureCube<uchar4>; >+native typedef TextureCube<ushort>; >+native typedef TextureCube<ushort2>; >+native typedef TextureCube<ushort3>; >+native typedef TextureCube<ushort4>; >+native typedef TextureCube<uint>; >+native typedef TextureCube<uint2>; >+native typedef TextureCube<uint3>; >+native typedef TextureCube<uint4>; >+native typedef TextureCube<char>; >+native typedef TextureCube<char2>; >+native typedef TextureCube<char3>; >+native typedef TextureCube<char4>; >+native typedef TextureCube<short>; >+native typedef TextureCube<short2>; >+native typedef TextureCube<short3>; >+native typedef TextureCube<short4>; >+native typedef TextureCube<int>; >+native typedef TextureCube<int2>; >+native typedef TextureCube<int3>; >+native typedef TextureCube<int4>; >+native typedef TextureCube<half>; >+native typedef TextureCube<half2>; >+native typedef TextureCube<half3>; >+native typedef TextureCube<half4>; >+native typedef TextureCube<float>; >+native typedef TextureCube<float2>; >+native typedef TextureCube<float3>; >+native typedef TextureCube<float4>; >+native typedef TextureDepth2D<float>; >+native typedef TextureDepth2D<half>; >+native typedef RWTextureDepth2D<float>; >+native typedef RWTextureDepth2D<half>; >+native typedef TextureDepth2DArray<float>; >+native typedef TextureDepth2DArray<half>; >+native typedef RWTextureDepth2DArray<float>; >+native typedef RWTextureDepth2DArray<half>; >+native typedef TextureDepthCube<float>; >+native typedef TextureDepthCube<half>; >+ >+// FIXME: Insert the rest of the standard library once the parser is fast enough >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >index e78451dd56b069b48b23e8b6d2fe6d3f52c91118..b0f5fdbe5ea3ce3a8169820bcd689c2a692dfa16 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >@@ -74,7 +74,7 @@ Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(WebGPUBindGroupLa > RefPtr<WebGPUShaderModule> WebGPUDevice::createShaderModule(WebGPUShaderModuleDescriptor&& descriptor) const > { > // FIXME: What can be validated here? >- auto module = m_device->createShaderModule(GPUShaderModuleDescriptor { descriptor.code }); >+ auto module = m_device->createShaderModule(GPUShaderModuleDescriptor { descriptor.code, descriptor.isWHLSL }); > return module ? WebGPUShaderModule::create(module.releaseNonNull()) : nullptr; > } > >diff --git a/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h b/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h >index af32a989ed5c506df3a7dcb09355ce52684c308f..b8d9817cd0a94fbbafcd5388f45970af65155412 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.h >@@ -33,6 +33,7 @@ namespace WebCore { > > struct WebGPUShaderModuleDescriptor { > String code; >+ bool isWHLSL; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.idl b/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.idl >index 32d707ed92b552426cb541aef48c8b5ea4da635f..971352ab04749655dc1a2fb0b287640381beb25a 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.idl >+++ b/Source/WebCore/Modules/webgpu/WebGPUShaderModuleDescriptor.idl >@@ -29,4 +29,5 @@ > EnabledAtRuntime=WebGPU > ] dictionary WebGPUShaderModuleDescriptor { > /*ArrayBuffer*/ DOMString code; // FIXME: DOMString for MTL prototyping only. >+ boolean isWHLSL = false; > }; >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 2cc9793da7d87781ec27fca3a52974c149ac2ebf..47548e153ca9a8fd6d306f2f3daf857d97adff7c 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -302,6 +302,7 @@ Modules/websockets/WorkerThreadableWebSocketChannel.cpp > > Modules/webgpu/DOMWindowWebGPU.cpp > Modules/webgpu/WHLSL/WHLSLLexer.cpp >+Modules/webgpu/WHLSL/WHLSLParser.cpp > Modules/webgpu/WebGPU.cpp > Modules/webgpu/WebGPUAdapter.cpp > Modules/webgpu/WebGPUBindGroupLayout.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 62cacafcd7bd4c368c1a407d515e4e2d535066b5..d23cf5bc01e570dce23b4358749bfd079b35edb5 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -6405,6 +6405,30 @@ > 1C3969CF1B74211E002BCFA7 /* FontCacheCoreText.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCacheCoreText.cpp; sourceTree = "<group>"; }; > 1C66260E1C6E7CA600AB527C /* FontFace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontFace.cpp; sourceTree = "<group>"; }; > 1C66260F1C6E7CA600AB527C /* FontFace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontFace.h; sourceTree = "<group>"; }; >+ 1C80596B21BA164A006B0906 /* WHLSLASTNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTNode.h; sourceTree = "<group>"; }; >+ 1C80596F21BB02D3006B0906 /* WHLSLASTPointerType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTPointerType.h; sourceTree = "<group>"; }; >+ 1C80597221BB02EA006B0906 /* WHLSLASTArrayReferenceType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTArrayReferenceType.h; sourceTree = "<group>"; }; >+ 1C80597421BB02FB006B0906 /* WHLSLASTArrayType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTArrayType.h; sourceTree = "<group>"; }; >+ 1C80597621BB0577006B0906 /* WHLSLASTReferenceType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTReferenceType.h; sourceTree = "<group>"; }; >+ 1C80597D21BF55A7006B0906 /* WHLSLASTBaseSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBaseSemantic.h; sourceTree = "<group>"; }; >+ 1C80598021BF55BA006B0906 /* WHLSLASTBuiltInSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBuiltInSemantic.h; sourceTree = "<group>"; }; >+ 1C80598221BF55D1006B0906 /* WHLSLASTResourceSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTResourceSemantic.h; sourceTree = "<group>"; }; >+ 1C80598421BF55ED006B0906 /* WHLSLASTSpecializationConstantSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTSpecializationConstantSemantic.h; sourceTree = "<group>"; }; >+ 1C80598621BF5601006B0906 /* WHLSLASTStageInOutSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTStageInOutSemantic.h; sourceTree = "<group>"; }; >+ 1C80598721BF5781006B0906 /* WHLSLASTSemantic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTSemantic.h; sourceTree = "<group>"; }; >+ 1C80598D21C1FD74006B0906 /* WHLSLASTIfStatement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTIfStatement.h; sourceTree = "<group>"; }; >+ 1C80598F21C1FD83006B0906 /* WHLSLASTSwitchStatement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTSwitchStatement.h; sourceTree = "<group>"; }; >+ 1C80599021C1FDAD006B0906 /* WHLSLASTSwitchCase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTSwitchCase.h; sourceTree = "<group>"; }; >+ 1C80599121C1FDC3006B0906 /* WHLSLASTForLoop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTForLoop.h; sourceTree = "<group>"; }; >+ 1C80599221C1FDDA006B0906 /* WHLSLASTWhileLoop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTWhileLoop.h; sourceTree = "<group>"; }; >+ 1C80599321C1FDE8006B0906 /* WHLSLASTDoWhileLoop.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTDoWhileLoop.h; sourceTree = "<group>"; }; >+ 1C80599421C1FDFE006B0906 /* WHLSLASTBreak.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBreak.h; sourceTree = "<group>"; }; >+ 1C80599521C1FE07006B0906 /* WHLSLASTContinue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTContinue.h; sourceTree = "<group>"; }; >+ 1C80599621C1FE14006B0906 /* WHLSLASTFallthrough.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTFallthrough.h; sourceTree = "<group>"; }; >+ 1C80599721C1FE20006B0906 /* WHLSLASTTrap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTTrap.h; sourceTree = "<group>"; }; >+ 1C80599821C1FE2E006B0906 /* WHLSLASTReturn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTReturn.h; sourceTree = "<group>"; }; >+ 1C80599A21C1FEA0006B0906 /* WHLSLASTStatement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTStatement.h; sourceTree = "<group>"; }; >+ 1C80599C21C2009D006B0906 /* WHLSLASTBlock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBlock.h; sourceTree = "<group>"; }; > 1C81B9560E97330800266E07 /* InspectorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorController.h; sourceTree = "<group>"; }; > 1C81B9570E97330800266E07 /* InspectorController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorController.cpp; sourceTree = "<group>"; }; > 1C81B9580E97330800266E07 /* InspectorClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorClient.h; sourceTree = "<group>"; }; >@@ -6416,6 +6440,8 @@ > 1CAF34800A6C405200ABE06E /* WebScriptObjectPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObjectPrivate.h; sourceTree = "<group>"; }; > 1CB6B4F8217B83930093B9CD /* TextDecorationThickness.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextDecorationThickness.h; sourceTree = "<group>"; }; > 1CB6B4FB217B83940093B9CD /* TextUnderlineOffset.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TextUnderlineOffset.h; sourceTree = "<group>"; }; >+ 1CC46F2721B77860000998DE /* WHLSLASTTypeReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTTypeReference.h; sourceTree = "<group>"; }; >+ 1CC46F2921B77A32000998DE /* WHLSLASTTypeArgument.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTTypeArgument.h; sourceTree = "<group>"; }; > 1CCDF5BB1990332400BCEBAD /* SVGToOTFFontConversion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGToOTFFontConversion.cpp; sourceTree = "<group>"; }; > 1CCDF5BC1990332400BCEBAD /* SVGToOTFFontConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGToOTFFontConversion.h; sourceTree = "<group>"; }; > 1CDD45E40BA9C84600F90147 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; }; >@@ -13216,9 +13242,42 @@ > C210E91221B4BD1000B7F83D /* WHLSLLexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLexer.h; sourceTree = "<group>"; }; > C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; }; > C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontVariationValue.h; sourceTree = "<group>"; }; >+ C22F76C021C0A45800C5434E /* WHLSLASTExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTExpression.h; sourceTree = "<group>"; }; >+ C22F76C121C0A63E00C5434E /* WHLSLASTCommaExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTCommaExpression.h; sourceTree = "<group>"; }; >+ C22F76C221C0A6DE00C5434E /* WHLSLASTTernaryExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTTernaryExpression.h; sourceTree = "<group>"; }; >+ C22F76C321C0A75500C5434E /* WHLSLASTAssignmentExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTAssignmentExpression.h; sourceTree = "<group>"; }; >+ C22F76C421C0A76300C5434E /* WHLSLASTReadModifyWriteExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTReadModifyWriteExpression.h; sourceTree = "<group>"; }; >+ C22F76C521C0A7AE00C5434E /* WHLSLASTLogicalExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTLogicalExpression.h; sourceTree = "<group>"; }; >+ C22F76C621C0A7BD00C5434E /* WHLSLASTCallExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTCallExpression.h; sourceTree = "<group>"; }; >+ C22F76C721C0A8CF00C5434E /* WHLSLASTDereferenceExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTDereferenceExpression.h; sourceTree = "<group>"; }; >+ C22F76C821C0A8E000C5434E /* WHLSLASTMakePointerExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTMakePointerExpression.h; sourceTree = "<group>"; }; >+ C22F76C921C0A8F200C5434E /* WHLSLASTMakeArrayReferenceExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTMakeArrayReferenceExpression.h; sourceTree = "<group>"; }; >+ C22F76CA21C0A90400C5434E /* WHLSLASTLogicalNotExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTLogicalNotExpression.h; sourceTree = "<group>"; }; >+ C22F76CB21C0A98B00C5434E /* WHLSLASTNullLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTNullLiteral.h; sourceTree = "<group>"; }; >+ C22F76CC21C0A9A700C5434E /* WHLSLASTVariableReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTVariableReference.h; sourceTree = "<group>"; }; >+ C22F76CD21C0A9BA00C5434E /* WHLSLASTIntegerLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTIntegerLiteral.h; sourceTree = "<group>"; }; >+ C22F76CE21C0A9C900C5434E /* WHLSLASTUnsignedIntegerLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTUnsignedIntegerLiteral.h; sourceTree = "<group>"; }; >+ C22F76CF21C0A9F100C5434E /* WHLSLASTFloatLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTFloatLiteral.h; sourceTree = "<group>"; }; >+ C22F76D021C0AA1400C5434E /* WHLSLASTBooleanLiteral.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBooleanLiteral.h; sourceTree = "<group>"; }; >+ C22F76D121C0AA5300C5434E /* WHLSLASTDotExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTDotExpression.h; sourceTree = "<group>"; }; >+ C22F76D221C0AA6300C5434E /* WHLSLASTIndexExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTIndexExpression.h; sourceTree = "<group>"; }; >+ C22F76D321C0AC5300C5434E /* WHLSLASTAnonymousVariableDeclaration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTAnonymousVariableDeclaration.h; sourceTree = "<group>"; }; >+ C22F76D421C0AFCF00C5434E /* WHLSLASTPropertyAccessExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTPropertyAccessExpression.h; sourceTree = "<group>"; }; >+ C22F76DD21C2508500C5434E /* WHLSLASTConstantExpressionEnumerationMemberReference.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTConstantExpressionEnumerationMemberReference.h; sourceTree = "<group>"; }; >+ C22F76DE21C2512800C5434E /* WHLSLASTConstantExpression.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTConstantExpression.h; sourceTree = "<group>"; }; >+ C22F76DF21C26F4700C5434E /* WHLSLASTVariableDeclarationsStatement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTVariableDeclarationsStatement.h; sourceTree = "<group>"; }; >+ C22F76E021C26F5B00C5434E /* WHLSLASTEffectfulExpressionStatement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTEffectfulExpressionStatement.h; sourceTree = "<group>"; }; > C2458E611FE8979E00594759 /* FontCacheCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontCacheCoreText.h; sourceTree = "<group>"; }; > C26017A11C72DC9900F74A16 /* CSSFontFaceSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFaceSet.cpp; sourceTree = "<group>"; }; > C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFaceSet.h; sourceTree = "<group>"; }; >+ C274F13521C032D6003410BD /* WHLSLASTFunctionDeclaration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTFunctionDeclaration.h; sourceTree = "<group>"; }; >+ C274F13721C03E95003410BD /* WHLSLASTBaseFunctionAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTBaseFunctionAttribute.h; sourceTree = "<group>"; }; >+ C274F13921C03EAC003410BD /* WHLSLASTNumThreadsFunctionAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTNumThreadsFunctionAttribute.h; sourceTree = "<group>"; }; >+ C274F13B21C03EBF003410BD /* WHLSLASTFunctionAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTFunctionAttribute.h; sourceTree = "<group>"; }; >+ C274F13D21C04AD5003410BD /* WHLSLASTParameter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTParameter.h; sourceTree = "<group>"; }; >+ C274F13F21C04D57003410BD /* WHLSLASTValue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTValue.h; sourceTree = "<group>"; }; >+ C274F14321C335FF003410BD /* WHLSLStandardLibrary.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = WHLSLStandardLibrary.txt; sourceTree = "<group>"; }; >+ C274F14521C33AC1003410BD /* WHLSLStandardLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WHLSLStandardLibrary.h; path = DerivedSources/WebCore/WHLSLStandardLibrary.h; sourceTree = BUILT_PRODUCTS_DIR; }; > C280833C1C6DB194001451B6 /* FontFace.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FontFace.idl; sourceTree = "<group>"; }; > C280833D1C6DC22C001451B6 /* JSFontFace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSFontFace.cpp; path = DerivedSources/WebCore/JSFontFace.cpp; sourceTree = BUILT_PRODUCTS_DIR; }; > C280833E1C6DC22C001451B6 /* JSFontFace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSFontFace.h; path = DerivedSources/WebCore/JSFontFace.h; sourceTree = BUILT_PRODUCTS_DIR; }; >@@ -13231,6 +13290,20 @@ > C2E38EFC1E8396FD00CA3ADF /* CSSFontStyleValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontStyleValue.h; sourceTree = "<group>"; }; > C2E38EFF1E84573500CA3ADF /* CSSFontStyleRangeValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontStyleRangeValue.cpp; sourceTree = "<group>"; }; > C2E38F001E84573500CA3ADF /* CSSFontStyleRangeValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontStyleRangeValue.h; sourceTree = "<group>"; }; >+ C2ECEB4C21B63CBB008F8DE9 /* WHLSLParser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLParser.cpp; sourceTree = "<group>"; }; >+ C2ECEB4D21B63CBB008F8DE9 /* WHLSLParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLParser.h; sourceTree = "<group>"; }; >+ C2ECEB5021B64C72008F8DE9 /* WHLSLASTVariableDeclaration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTVariableDeclaration.h; sourceTree = "<group>"; }; >+ C2ECEB5221B64C84008F8DE9 /* WHLSLASTTypeDefinition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTTypeDefinition.h; sourceTree = "<group>"; }; >+ C2ECEB5421B64C97008F8DE9 /* WHLSLASTStructureDefinition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTStructureDefinition.h; sourceTree = "<group>"; }; >+ C2ECEB5621B64CAB008F8DE9 /* WHLSLASTEnumerationDefinition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTEnumerationDefinition.h; sourceTree = "<group>"; }; >+ C2ECEB5821B64CBE008F8DE9 /* WHLSLASTFunctionDefinition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTFunctionDefinition.h; sourceTree = "<group>"; }; >+ C2ECEB5A21B64CD5008F8DE9 /* WHLSLASTNativeFunctionDeclaration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTNativeFunctionDeclaration.h; sourceTree = "<group>"; }; >+ C2ECEB5C21B64CE4008F8DE9 /* WHLSLASTNativeTypeDeclaration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTNativeTypeDeclaration.h; sourceTree = "<group>"; }; >+ C2ECEB5E21B64D6F008F8DE9 /* WHLSLProgram.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLProgram.h; sourceTree = "<group>"; }; >+ C2ECEB6021B64DC6008F8DE9 /* WHLSLASTType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTType.h; sourceTree = "<group>"; }; >+ C2ECEB6C21BE4896008F8DE9 /* WHLSLASTStructureElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTStructureElement.h; sourceTree = "<group>"; }; >+ C2ECEB7421BF7F3A008F8DE9 /* WHLSLASTQualifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTQualifier.h; sourceTree = "<group>"; }; >+ C2ECEB7921BF8E05008F8DE9 /* WHLSLASTEnumerationMember.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLASTEnumerationMember.h; sourceTree = "<group>"; }; > C2F4E7881E45AEDF006D7105 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; }; > C2F4E7891E45AEDF006D7105 /* ComplexTextController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ComplexTextController.h; sourceTree = "<group>"; }; > C330A22113EC196B0000B45B /* ColorChooser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorChooser.h; sourceTree = "<group>"; }; >@@ -19607,6 +19680,7 @@ > 656581AF09D14EE6000E61D7 /* UserAgentStyleSheetsData.cpp */, > 1A1414B313A0F0500019996C /* WebKitFontFamilyNames.cpp */, > 1A1414B413A0F0500019996C /* WebKitFontFamilyNames.h */, >+ C274F14521C33AC1003410BD /* WHLSLStandardLibrary.h */, > 51748FA21CC6EEEB00728D84 /* WorkerGlobalScopeConstructors.idl */, > 9908B0F91BCAD07D00ED0F75 /* WritableStreamBuiltins.cpp */, > 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */, >@@ -25228,6 +25302,95 @@ > path = WHLSL; > sourceTree = "<group>"; > }; >+ C210E90D21B4BCA400B7F83D /* WHLSL */ = { >+ isa = PBXGroup; >+ children = ( >+ C22F76E221C2ED6000C5434E /* AST */, >+ C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */, >+ C210E91221B4BD1000B7F83D /* WHLSLLexer.h */, >+ C2ECEB4C21B63CBB008F8DE9 /* WHLSLParser.cpp */, >+ C2ECEB4D21B63CBB008F8DE9 /* WHLSLParser.h */, >+ C2ECEB5E21B64D6F008F8DE9 /* WHLSLProgram.h */, >+ C274F14321C335FF003410BD /* WHLSLStandardLibrary.txt */, >+ ); >+ path = WHLSL; >+ sourceTree = "<group>"; >+ }; >+ C22F76E221C2ED6000C5434E /* AST */ = { >+ isa = PBXGroup; >+ children = ( >+ C22F76D321C0AC5300C5434E /* WHLSLASTAnonymousVariableDeclaration.h */, >+ 1C80597221BB02EA006B0906 /* WHLSLASTArrayReferenceType.h */, >+ 1C80597421BB02FB006B0906 /* WHLSLASTArrayType.h */, >+ C22F76C321C0A75500C5434E /* WHLSLASTAssignmentExpression.h */, >+ C274F13721C03E95003410BD /* WHLSLASTBaseFunctionAttribute.h */, >+ 1C80597D21BF55A7006B0906 /* WHLSLASTBaseSemantic.h */, >+ 1C80599C21C2009D006B0906 /* WHLSLASTBlock.h */, >+ C22F76D021C0AA1400C5434E /* WHLSLASTBooleanLiteral.h */, >+ 1C80599421C1FDFE006B0906 /* WHLSLASTBreak.h */, >+ 1C80598021BF55BA006B0906 /* WHLSLASTBuiltInSemantic.h */, >+ C22F76C621C0A7BD00C5434E /* WHLSLASTCallExpression.h */, >+ C22F76C121C0A63E00C5434E /* WHLSLASTCommaExpression.h */, >+ C22F76DE21C2512800C5434E /* WHLSLASTConstantExpression.h */, >+ C22F76DD21C2508500C5434E /* WHLSLASTConstantExpressionEnumerationMemberReference.h */, >+ 1C80599521C1FE07006B0906 /* WHLSLASTContinue.h */, >+ C22F76C721C0A8CF00C5434E /* WHLSLASTDereferenceExpression.h */, >+ C22F76D121C0AA5300C5434E /* WHLSLASTDotExpression.h */, >+ 1C80599321C1FDE8006B0906 /* WHLSLASTDoWhileLoop.h */, >+ C22F76E021C26F5B00C5434E /* WHLSLASTEffectfulExpressionStatement.h */, >+ C2ECEB5621B64CAB008F8DE9 /* WHLSLASTEnumerationDefinition.h */, >+ C2ECEB7921BF8E05008F8DE9 /* WHLSLASTEnumerationMember.h */, >+ C22F76C021C0A45800C5434E /* WHLSLASTExpression.h */, >+ 1C80599621C1FE14006B0906 /* WHLSLASTFallthrough.h */, >+ C22F76CF21C0A9F100C5434E /* WHLSLASTFloatLiteral.h */, >+ 1C80599121C1FDC3006B0906 /* WHLSLASTForLoop.h */, >+ C274F13B21C03EBF003410BD /* WHLSLASTFunctionAttribute.h */, >+ C274F13521C032D6003410BD /* WHLSLASTFunctionDeclaration.h */, >+ C2ECEB5821B64CBE008F8DE9 /* WHLSLASTFunctionDefinition.h */, >+ 1C80598D21C1FD74006B0906 /* WHLSLASTIfStatement.h */, >+ C22F76D221C0AA6300C5434E /* WHLSLASTIndexExpression.h */, >+ C22F76CD21C0A9BA00C5434E /* WHLSLASTIntegerLiteral.h */, >+ C22F76C521C0A7AE00C5434E /* WHLSLASTLogicalExpression.h */, >+ C22F76CA21C0A90400C5434E /* WHLSLASTLogicalNotExpression.h */, >+ C22F76C921C0A8F200C5434E /* WHLSLASTMakeArrayReferenceExpression.h */, >+ C22F76C821C0A8E000C5434E /* WHLSLASTMakePointerExpression.h */, >+ C2ECEB5A21B64CD5008F8DE9 /* WHLSLASTNativeFunctionDeclaration.h */, >+ C2ECEB5C21B64CE4008F8DE9 /* WHLSLASTNativeTypeDeclaration.h */, >+ 1C80596B21BA164A006B0906 /* WHLSLASTNode.h */, >+ C22F76CB21C0A98B00C5434E /* WHLSLASTNullLiteral.h */, >+ C274F13921C03EAC003410BD /* WHLSLASTNumThreadsFunctionAttribute.h */, >+ C274F13D21C04AD5003410BD /* WHLSLASTParameter.h */, >+ 1C80596F21BB02D3006B0906 /* WHLSLASTPointerType.h */, >+ C22F76D421C0AFCF00C5434E /* WHLSLASTPropertyAccessExpression.h */, >+ C2ECEB7421BF7F3A008F8DE9 /* WHLSLASTQualifier.h */, >+ C22F76C421C0A76300C5434E /* WHLSLASTReadModifyWriteExpression.h */, >+ 1C80597621BB0577006B0906 /* WHLSLASTReferenceType.h */, >+ 1C80598221BF55D1006B0906 /* WHLSLASTResourceSemantic.h */, >+ 1C80599821C1FE2E006B0906 /* WHLSLASTReturn.h */, >+ 1C80598721BF5781006B0906 /* WHLSLASTSemantic.h */, >+ 1C80598421BF55ED006B0906 /* WHLSLASTSpecializationConstantSemantic.h */, >+ 1C80598621BF5601006B0906 /* WHLSLASTStageInOutSemantic.h */, >+ 1C80599A21C1FEA0006B0906 /* WHLSLASTStatement.h */, >+ C2ECEB5421B64C97008F8DE9 /* WHLSLASTStructureDefinition.h */, >+ C2ECEB6C21BE4896008F8DE9 /* WHLSLASTStructureElement.h */, >+ 1C80599021C1FDAD006B0906 /* WHLSLASTSwitchCase.h */, >+ 1C80598F21C1FD83006B0906 /* WHLSLASTSwitchStatement.h */, >+ C22F76C221C0A6DE00C5434E /* WHLSLASTTernaryExpression.h */, >+ 1C80599721C1FE20006B0906 /* WHLSLASTTrap.h */, >+ C2ECEB6021B64DC6008F8DE9 /* WHLSLASTType.h */, >+ 1CC46F2921B77A32000998DE /* WHLSLASTTypeArgument.h */, >+ C2ECEB5221B64C84008F8DE9 /* WHLSLASTTypeDefinition.h */, >+ 1CC46F2721B77860000998DE /* WHLSLASTTypeReference.h */, >+ C22F76CE21C0A9C900C5434E /* WHLSLASTUnsignedIntegerLiteral.h */, >+ C274F13F21C04D57003410BD /* WHLSLASTValue.h */, >+ C2ECEB5021B64C72008F8DE9 /* WHLSLASTVariableDeclaration.h */, >+ C22F76DF21C26F4700C5434E /* WHLSLASTVariableDeclarationsStatement.h */, >+ C22F76CC21C0A9A700C5434E /* WHLSLASTVariableReference.h */, >+ 1C80599221C1FDDA006B0906 /* WHLSLASTWhileLoop.h */, >+ ); >+ path = AST; >+ sourceTree = "<group>"; >+ }; > C96F5EBF1B5872260091EA9D /* mediasession */ = { > isa = PBXGroup; > children = ( >diff --git a/Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h b/Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h >index 6cfe0ad5a87b32c48ae34bd76d2f1c5981be7d5d..5c3ecf6a7c0111f2223cb9be2f44483869255fff 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUShaderModuleDescriptor.h >@@ -33,6 +33,7 @@ namespace WebCore { > > struct GPUShaderModuleDescriptor { > String code; >+ bool isWHLSL; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >index 4553a15df5fcc073fc1a54137f607c0ae11404a7..ba94fcf29332796bd168bd5ec8579d04161ba675 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >@@ -31,6 +31,9 @@ > #import "GPUDevice.h" > #import "GPUShaderModuleDescriptor.h" > #import "Logging.h" >+#import "WHLSLParser.h" >+#import "WHLSLProgram.h" >+#import "WHLSLStandardLibrary.h" > > #import <Metal/Metal.h> > #import <wtf/BlockObjCExceptions.h> >@@ -44,12 +47,25 @@ RefPtr<GPUShaderModule> GPUShaderModule::create(const GPUDevice& device, GPUShad > return nullptr; > } > >+ String code = descriptor.code; >+ >+ if (descriptor.isWHLSL) { >+ WHLSL::Program program; >+ WHLSL::Parser parser; >+ auto standardLibrary = String::fromUTF8(WHLSLStandardLibrary, sizeof(WHLSLStandardLibrary)); >+ if (parser.parse(program, standardLibrary, WHLSL::Parser::Mode::StandardLibrary) == std::nullopt >+ && parser.parse(program, descriptor.code, WHLSL::Parser::Mode::User) == std::nullopt) >+ code = ""; >+ else >+ return nullptr; >+ } >+ > PlatformShaderModuleSmartPtr module; > > BEGIN_BLOCK_OBJC_EXCEPTIONS; > > NSError *error = [NSError errorWithDomain:@"com.apple.WebKit.GPU" code:1 userInfo:nil]; >- module = adoptNS([device.platformDevice() newLibraryWithSource:descriptor.code options:nil error:&error]); >+ module = adoptNS([device.platformDevice() newLibraryWithSource:code options:nil error:&error]); > if (!module) > LOG(WebGPU, "Shader compilation error: %s", [[error localizedDescription] UTF8String]); > >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 83e0dcf84cb191413dcaa4e71b5cf67e2bd8c5d0..da161bb743b3b5cda91daeeb6488d3f16f95e642 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,13 @@ >+2018-12-19 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ [WHLSL] Add a handwritten parser >+ https://bugs.webkit.org/show_bug.cgi?id=192355 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * webgpu/WHLSL/parse-expected.txt: Added. >+ * webgpu/WHLSL/parse.html: Added. >+ > 2018-12-19 Tim Horton <timothy_horton@apple.com> > > UI process crash when focusing an editable image >diff --git a/LayoutTests/platform/gtk/TestExpectations b/LayoutTests/platform/gtk/TestExpectations >index 992d571642fa16b62719c719a7fc2e2fe1865c5d..71cd6f6721ee43b00cb5ec5020b0d2d0c3e5b9e4 100644 >--- a/LayoutTests/platform/gtk/TestExpectations >+++ b/LayoutTests/platform/gtk/TestExpectations >@@ -3586,14 +3586,7 @@ webkit.org/b/191003 imported/w3c/web-platform-tests/mimesniff/mime-types/charset > > webkit.org/b/191004 media/track/track-cue-missing.html [ Failure ] > >-webkit.org/b/191005 webgpu/webgpu-enabled.html [ Failure ] >-webkit.org/b/191005 webgpu/render-pipelines.html [ Failure ] >-webkit.org/b/191005 webgpu/shader-modules.html [ Failure ] >-webkit.org/b/191005 webgpu/webgpu-basics.html [ Failure ] >-webkit.org/b/191005 webgpu/command-buffers.html [ Failure ] >-webkit.org/b/191005 webgpu/queue-creation.html [ Failure ] >-webkit.org/b/191005 webgpu/render-passes.html [ Failure ] >-webkit.org/b/191005 webgpu/textures-textureviews.html [ Failure ] >+webkit.org/b/191005 webgpu [ Skip ] > > webkit.org/b/191006 webrtc/simulcast-h264.html [ Failure ] > >diff --git a/LayoutTests/webgpu/WHLSL/parse-expected.txt b/LayoutTests/webgpu/WHLSL/parse-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..a290b5aaa2893cb14462d8ee9f8ce438de7ab516 >--- /dev/null >+++ b/LayoutTests/webgpu/WHLSL/parse-expected.txt >@@ -0,0 +1,6 @@ >+PASS shaderModule is defined. >+PASS shaderModule is non-null. >+PASS successfullyParsed is true >+ >+TEST COMPLETE >+ >diff --git a/LayoutTests/webgpu/WHLSL/parse.html b/LayoutTests/webgpu/WHLSL/parse.html >new file mode 100644 >index 0000000000000000000000000000000000000000..f75a43a5c790e7e1e4a57e1d4db3f97b5aea468e >--- /dev/null >+++ b/LayoutTests/webgpu/WHLSL/parse.html >@@ -0,0 +1,19 @@ >+<!DOCTYPE html> >+<html> >+<head> >+<script src="../../resources/js-test-pre.js"></script> >+</head> >+<body> >+<script> >+let shaderSource = ""; >+let shaderModule; >+window.webgpu.requestAdapter({}).then(function(adapter) { >+ let device = adapter.createDevice(); >+ shaderModule = device.createShaderModule({ code: shaderSource, isWHLSL: true }); >+ shouldBeDefined("shaderModule"); >+ shouldBeNonNull("shaderModule"); >+}); >+</script> >+<script src="../../resources/js-test-post.js"></script> >+</body> >+</html>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192355
:
356468
|
356569
|
356570
|
356585
|
356695
|
356778
|
356863
|
356947
|
357031
|
357035
|
357038
|
357081
|
357103
|
357199
|
357207
|
357225
|
357245
|
357268
|
357277
|
357303
|
357304
|
357361
|
357410
|
357430
|
357458
|
357520
|
357602
|
357749
|
357754
|
357765
|
357869
|
357889
|
357929
|
357932
|
357975
|
358866
|
358880
|
358902
|
359250