[WHLSL] Track code locations correctly throughout the compiler to get good error...
authorrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jul 2019 22:33:56 +0000 (22:33 +0000)
committerrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Jul 2019 22:33:56 +0000 (22:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=199675

Reviewed by Myles Maxfield.

The basic idea is to go from having each AST node contain its own token to having each AST node contain a pair of offsets into the source,
the offset before its start and the offset after its end. This will let us get good error messages.
As a bonus, it saves a bit of memory as Tokens are larger (one extra word for their type).

The new CodeLocation class is put in Lexer.h, because it has a cyclic dependency on Token, which also has a cyclic dependency on Lexer.

No new tests as there is no intended functional change.

* Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
(WebCore::WHLSL::AST::ArrayReferenceType::ArrayReferenceType):
* Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
(WebCore::WHLSL::AST::ArrayType::ArrayType):
* Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h:
(WebCore::WHLSL::AST::AssignmentExpression::AssignmentExpression):
* Modules/webgpu/WHLSL/AST/WHLSLBaseFunctionAttribute.h:
(WebCore::WHLSL::AST::BaseFunctionAttribute::BaseFunctionAttribute):
* Modules/webgpu/WHLSL/AST/WHLSLBaseSemantic.h:
(WebCore::WHLSL::AST::BaseSemantic::BaseSemantic):
* Modules/webgpu/WHLSL/AST/WHLSLBlock.h:
(WebCore::WHLSL::AST::Block::Block):
* Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h:
(WebCore::WHLSL::AST::BooleanLiteral::BooleanLiteral):
(WebCore::WHLSL::AST::BooleanLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLBreak.h:
(WebCore::WHLSL::AST::Break::Break):
* Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.h:
(WebCore::WHLSL::AST::BuiltInSemantic::BuiltInSemantic):
* Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
(WebCore::WHLSL::AST::CallExpression::CallExpression):
* Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h:
(WebCore::WHLSL::AST::CommaExpression::CommaExpression):
* Modules/webgpu/WHLSL/AST/WHLSLContinue.h:
(WebCore::WHLSL::AST::Continue::Continue):
* Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h:
(WebCore::WHLSL::AST::DereferenceExpression::DereferenceExpression):
* Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h:
(WebCore::WHLSL::AST::DoWhileLoop::DoWhileLoop):
* Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h:
(WebCore::WHLSL::AST::DotExpression::DotExpression):
* Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h:
(WebCore::WHLSL::AST::EffectfulExpressionStatement::EffectfulExpressionStatement):
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
(WebCore::WHLSL::AST::EnumerationDefinition::EnumerationDefinition):
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h:
(WebCore::WHLSL::AST::EnumerationMember::EnumerationMember):
(WebCore::WHLSL::AST::EnumerationMember::codeLocation const):
* Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h:
(WebCore::WHLSL::AST::EnumerationMemberLiteral::EnumerationMemberLiteral):
(WebCore::WHLSL::AST::EnumerationMemberLiteral::wrap):
(WebCore::WHLSL::AST::EnumerationMemberLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLExpression.h:
(WebCore::WHLSL::AST::Expression::Expression):
(WebCore::WHLSL::AST::Expression::codeLocation const):
(WebCore::WHLSL::AST::Expression::updateCodeLocation):
* Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h:
(WebCore::WHLSL::AST::Fallthrough::Fallthrough):
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h:
(WebCore::WHLSL::AST::FloatLiteral::FloatLiteral):
(WebCore::WHLSL::AST::FloatLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp:
(WebCore::WHLSL::AST::FloatLiteralType::FloatLiteralType):
(WebCore::WHLSL::AST::FloatLiteralType::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h:
* Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
(WebCore::WHLSL::AST::ForLoop::ForLoop):
* Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h:
(WebCore::WHLSL::AST::FunctionDeclaration::FunctionDeclaration):
(WebCore::WHLSL::AST::FunctionDeclaration::codeLocation const):
* Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h:
(WebCore::WHLSL::AST::GlobalVariableReference::GlobalVariableReference):
* Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h:
(WebCore::WHLSL::AST::IfStatement::IfStatement):
* Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
(WebCore::WHLSL::AST::IndexExpression::IndexExpression):
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h:
(WebCore::WHLSL::AST::IntegerLiteral::IntegerLiteral):
(WebCore::WHLSL::AST::IntegerLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp:
(WebCore::WHLSL::AST::IntegerLiteralType::IntegerLiteralType):
(WebCore::WHLSL::AST::IntegerLiteralType::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h:
* Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h:
(WebCore::WHLSL::AST::LogicalExpression::LogicalExpression):
* Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h:
(WebCore::WHLSL::AST::LogicalNotExpression::LogicalNotExpression):
* Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
(WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression):
* Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
(WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression):
* Modules/webgpu/WHLSL/AST/WHLSLNamedType.h:
(WebCore::WHLSL::AST::NamedType::NamedType):
(WebCore::WHLSL::AST::NamedType::codeLocation const):
(WebCore::WHLSL::AST::NamedType::updateCodeLocation):
* Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h:
(WebCore::WHLSL::AST::NativeTypeDeclaration::NativeTypeDeclaration):
* Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h:
(WebCore::WHLSL::AST::NullLiteral::NullLiteral):
(WebCore::WHLSL::AST::NullLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLNumThreadsFunctionAttribute.h:
(WebCore::WHLSL::AST::NumThreadsFunctionAttribute::NumThreadsFunctionAttribute):
* Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
(WebCore::WHLSL::AST::PointerType::PointerType):
* Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
(WebCore::WHLSL::AST::PropertyAccessExpression::PropertyAccessExpression):
* Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h:
(WebCore::WHLSL::AST::ReadModifyWriteExpression::create):
(WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression):
* Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
(WebCore::WHLSL::AST::ReferenceType::ReferenceType):
* Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.h:
(WebCore::WHLSL::AST::ResourceSemantic::ResourceSemantic):
* Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
(WebCore::WHLSL::AST::Return::Return):
* Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.h:
(WebCore::WHLSL::AST::SpecializationConstantSemantic::SpecializationConstantSemantic):
* Modules/webgpu/WHLSL/AST/WHLSLStageInOutSemantic.h:
(WebCore::WHLSL::AST::StageInOutSemantic::StageInOutSemantic):
* Modules/webgpu/WHLSL/AST/WHLSLStatement.h:
(WebCore::WHLSL::AST::Statement::Statement):
(WebCore::WHLSL::AST::Statement::codeLocation const):
(WebCore::WHLSL::AST::Statement::updateCodeLocation):
* Modules/webgpu/WHLSL/AST/WHLSLStatementList.h:
(WebCore::WHLSL::AST::StatementList::StatementList):
* Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h:
(WebCore::WHLSL::AST::StructureDefinition::StructureDefinition):
* Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h:
(WebCore::WHLSL::AST::StructureElement::StructureElement):
(WebCore::WHLSL::AST::StructureElement::codeLocation const):
* Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h:
(WebCore::WHLSL::AST::SwitchCase::SwitchCase):
* Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h:
(WebCore::WHLSL::AST::SwitchStatement::SwitchStatement):
* Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h:
(WebCore::WHLSL::AST::TernaryExpression::TernaryExpression):
* Modules/webgpu/WHLSL/AST/WHLSLTrap.h:
(WebCore::WHLSL::AST::Trap::Trap):
* Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h:
(WebCore::WHLSL::AST::TypeDefinition::TypeDefinition):
* Modules/webgpu/WHLSL/AST/WHLSLTypeReference.cpp:
(WebCore::WHLSL::AST::TypeReference::wrap):
* Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
(WebCore::WHLSL::AST::TypeReference::TypeReference):
(WebCore::WHLSL::AST::TypeReference::cloneTypeReference const):
* Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
(WebCore::WHLSL::AST::UnnamedType::UnnamedType):
(WebCore::WHLSL::AST::UnnamedType::codeLocation const):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h:
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::UnsignedIntegerLiteral):
(WebCore::WHLSL::AST::UnsignedIntegerLiteral::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp:
(WebCore::WHLSL::AST::UnsignedIntegerLiteralType::UnsignedIntegerLiteralType):
(WebCore::WHLSL::AST::UnsignedIntegerLiteralType::clone const):
* Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h:
* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h:
* Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h:
(WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement):
* Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h:
(WebCore::WHLSL::AST::VariableReference::VariableReference):
(WebCore::WHLSL::AST::VariableReference::wrap):
* Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h:
(WebCore::WHLSL::AST::WhileLoop::WhileLoop):
* Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp:
(WebCore::WHLSL::AutoInitialize::visit):
* Modules/webgpu/WHLSL/WHLSLChecker.cpp:
(WebCore::WHLSL::resolveWithOperatorAnderIndexer):
(WebCore::WHLSL::resolveWithOperatorLength):
(WebCore::WHLSL::resolveWithReferenceComparator):
(WebCore::WHLSL::resolveByInstantiation):
(WebCore::WHLSL::resolveFunction):
(WebCore::WHLSL::Checker::visit):
(WebCore::WHLSL::argumentTypeForAndOverload):
(WebCore::WHLSL::Checker::finishVisiting):
* Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
(WebCore::WHLSL::matchAndCommit):
* Modules/webgpu/WHLSL/WHLSLLexer.cpp:
(WebCore::WHLSL::Token::typeName):
(WebCore::WHLSL::Lexer::consumeTokenFromStream):
* Modules/webgpu/WHLSL/WHLSLLexer.h:
(WebCore::WHLSL::AST::CodeLocation::CodeLocation):
(WebCore::WHLSL::AST::CodeLocation::startOffset const):
(WebCore::WHLSL::AST::CodeLocation::endOffset const):
(WebCore::WHLSL::Token::startOffset const):
(WebCore::WHLSL::Lexer::errorString):
(WebCore::WHLSL::Token::stringView const):
* Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
(WebCore::WHLSL::NameResolver::visit):
* Modules/webgpu/WHLSL/WHLSLParser.cpp:
(WebCore::WHLSL::Parser::parse):
(WebCore::WHLSL::Parser::peek):
(WebCore::WHLSL::Parser::peekFurther):
(WebCore::WHLSL::Types::includes):
(WebCore::WHLSL::Types::appendNameTo):
(WebCore::WHLSL::Types<t>::includes):
(WebCore::WHLSL::Types<t>::appendNameTo):
(WebCore::WHLSL::Parser::peekType):
(WebCore::WHLSL::Parser::tryType):
(WebCore::WHLSL::Parser::tryTypes):
(WebCore::WHLSL::Parser::consumeType):
(WebCore::WHLSL::Parser::consumeTypes):
(WebCore::WHLSL::Parser::consumeIntegralLiteral):
(WebCore::WHLSL::Parser::parseConstantExpression):
(WebCore::WHLSL::Parser::parseTypeArgument):
(WebCore::WHLSL::Parser::parseTypeArguments):
(WebCore::WHLSL::Parser::parseTypeSuffixAbbreviated):
(WebCore::WHLSL::Parser::parseTypeSuffixNonAbbreviated):
(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::parseComputeFunctionDeclaration):
(WebCore::WHLSL::Parser::parseVertexOrFragmentFunctionDeclaration):
(WebCore::WHLSL::Parser::parseRegularFunctionDeclaration):
(WebCore::WHLSL::Parser::parseOperatorFunctionDeclaration):
(WebCore::WHLSL::Parser::parseFunctionDeclaration):
(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::parseLimitedSuffixOperator):
(WebCore::WHLSL::Parser::parseSuffixOperator):
(WebCore::WHLSL::Parser::parseExpression):
(WebCore::WHLSL::Parser::completeTernaryConditional):
(WebCore::WHLSL::Parser::completeAssignment):
(WebCore::WHLSL::Parser::parsePossibleTernaryConditional):
(WebCore::WHLSL::Parser::completePossibleLogicalBinaryOperation):
(WebCore::WHLSL::Parser::completePossibleRelationalBinaryOperation):
(WebCore::WHLSL::Parser::completePossibleShift):
(WebCore::WHLSL::Parser::completePossibleAdd):
(WebCore::WHLSL::Parser::completePossibleMultiply):
(WebCore::WHLSL::Parser::parsePossiblePrefix):
(WebCore::WHLSL::Parser::parsePossibleSuffix):
(WebCore::WHLSL::Parser::parseCallExpression):
(WebCore::WHLSL::Parser::parseTerm):
* Modules/webgpu/WHLSL/WHLSLParser.h:
* Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
(WebCore::WHLSL::anonymousToken):
(WebCore::WHLSL::PreserveLifetimes::PreserveLifetimes):
(WebCore::WHLSL::PreserveLifetimes::assignVariableIntoStruct):
(WebCore::WHLSL::preserveVariableLifetimes):
* Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
(WebCore::WHLSL::PropertyResolver::visit):
(WebCore::WHLSL::wrapAnderCallArgument):
(WebCore::WHLSL::setterCall):
(WebCore::WHLSL::getterCall):
(WebCore::WHLSL::modify):
(WebCore::WHLSL::PropertyResolver::simplifyRightValue):
(WebCore::WHLSL::LeftValueSimplifier::finishVisiting):
* Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
(WebCore::WHLSL::synthesizeArrayOperatorLength):
* Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp:
(WebCore::WHLSL::synthesizeConstructors):
* Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp:
(WebCore::WHLSL::synthesizeEnumerationFunctions):
* Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:
(WebCore::WHLSL::synthesizeStructureAccessors):

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

82 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBaseFunctionAttribute.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBaseSemantic.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBlock.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBreak.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLContinue.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLForLoop.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNamedType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLNumThreadsFunctionAttribute.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPointerType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReturn.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStageInOutSemantic.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStatementList.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTrap.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLChecker.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLInferTypes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLLexer.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLParser.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp

index f8c6b30..b78bd9e 100644 (file)
@@ -1,3 +1,288 @@
+2019-07-10  Robin Morisset  <rmorisset@apple.com>
+
+        [WHLSL] Track code locations correctly throughout the compiler to get good error messages
+        https://bugs.webkit.org/show_bug.cgi?id=199675
+
+        Reviewed by Myles Maxfield.
+
+        The basic idea is to go from having each AST node contain its own token to having each AST node contain a pair of offsets into the source,
+        the offset before its start and the offset after its end. This will let us get good error messages.
+        As a bonus, it saves a bit of memory as Tokens are larger (one extra word for their type).
+
+        The new CodeLocation class is put in Lexer.h, because it has a cyclic dependency on Token, which also has a cyclic dependency on Lexer.
+
+        No new tests as there is no intended functional change.
+
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
+        (WebCore::WHLSL::AST::ArrayReferenceType::ArrayReferenceType):
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
+        (WebCore::WHLSL::AST::ArrayType::ArrayType):
+        * Modules/webgpu/WHLSL/AST/WHLSLAssignmentExpression.h:
+        (WebCore::WHLSL::AST::AssignmentExpression::AssignmentExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLBaseFunctionAttribute.h:
+        (WebCore::WHLSL::AST::BaseFunctionAttribute::BaseFunctionAttribute):
+        * Modules/webgpu/WHLSL/AST/WHLSLBaseSemantic.h:
+        (WebCore::WHLSL::AST::BaseSemantic::BaseSemantic):
+        * Modules/webgpu/WHLSL/AST/WHLSLBlock.h:
+        (WebCore::WHLSL::AST::Block::Block):
+        * Modules/webgpu/WHLSL/AST/WHLSLBooleanLiteral.h:
+        (WebCore::WHLSL::AST::BooleanLiteral::BooleanLiteral):
+        (WebCore::WHLSL::AST::BooleanLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLBreak.h:
+        (WebCore::WHLSL::AST::Break::Break):
+        * Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.h:
+        (WebCore::WHLSL::AST::BuiltInSemantic::BuiltInSemantic):
+        * Modules/webgpu/WHLSL/AST/WHLSLCallExpression.h:
+        (WebCore::WHLSL::AST::CallExpression::CallExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLCommaExpression.h:
+        (WebCore::WHLSL::AST::CommaExpression::CommaExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLContinue.h:
+        (WebCore::WHLSL::AST::Continue::Continue):
+        * Modules/webgpu/WHLSL/AST/WHLSLDereferenceExpression.h:
+        (WebCore::WHLSL::AST::DereferenceExpression::DereferenceExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLDoWhileLoop.h:
+        (WebCore::WHLSL::AST::DoWhileLoop::DoWhileLoop):
+        * Modules/webgpu/WHLSL/AST/WHLSLDotExpression.h:
+        (WebCore::WHLSL::AST::DotExpression::DotExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLEffectfulExpressionStatement.h:
+        (WebCore::WHLSL::AST::EffectfulExpressionStatement::EffectfulExpressionStatement):
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationDefinition.h:
+        (WebCore::WHLSL::AST::EnumerationDefinition::EnumerationDefinition):
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationMember.h:
+        (WebCore::WHLSL::AST::EnumerationMember::EnumerationMember):
+        (WebCore::WHLSL::AST::EnumerationMember::codeLocation const):
+        * Modules/webgpu/WHLSL/AST/WHLSLEnumerationMemberLiteral.h:
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::EnumerationMemberLiteral):
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::wrap):
+        (WebCore::WHLSL::AST::EnumerationMemberLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLExpression.h:
+        (WebCore::WHLSL::AST::Expression::Expression):
+        (WebCore::WHLSL::AST::Expression::codeLocation const):
+        (WebCore::WHLSL::AST::Expression::updateCodeLocation):
+        * Modules/webgpu/WHLSL/AST/WHLSLFallthrough.h:
+        (WebCore::WHLSL::AST::Fallthrough::Fallthrough):
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteral.h:
+        (WebCore::WHLSL::AST::FloatLiteral::FloatLiteral):
+        (WebCore::WHLSL::AST::FloatLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.cpp:
+        (WebCore::WHLSL::AST::FloatLiteralType::FloatLiteralType):
+        (WebCore::WHLSL::AST::FloatLiteralType::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLFloatLiteralType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLForLoop.h:
+        (WebCore::WHLSL::AST::ForLoop::ForLoop):
+        * Modules/webgpu/WHLSL/AST/WHLSLFunctionDeclaration.h:
+        (WebCore::WHLSL::AST::FunctionDeclaration::FunctionDeclaration):
+        (WebCore::WHLSL::AST::FunctionDeclaration::codeLocation const):
+        * Modules/webgpu/WHLSL/AST/WHLSLGlobalVariableReference.h:
+        (WebCore::WHLSL::AST::GlobalVariableReference::GlobalVariableReference):
+        * Modules/webgpu/WHLSL/AST/WHLSLIfStatement.h:
+        (WebCore::WHLSL::AST::IfStatement::IfStatement):
+        * Modules/webgpu/WHLSL/AST/WHLSLIndexExpression.h:
+        (WebCore::WHLSL::AST::IndexExpression::IndexExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteral.h:
+        (WebCore::WHLSL::AST::IntegerLiteral::IntegerLiteral):
+        (WebCore::WHLSL::AST::IntegerLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.cpp:
+        (WebCore::WHLSL::AST::IntegerLiteralType::IntegerLiteralType):
+        (WebCore::WHLSL::AST::IntegerLiteralType::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLIntegerLiteralType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLLogicalExpression.h:
+        (WebCore::WHLSL::AST::LogicalExpression::LogicalExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLLogicalNotExpression.h:
+        (WebCore::WHLSL::AST::LogicalNotExpression::LogicalNotExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLMakeArrayReferenceExpression.h:
+        (WebCore::WHLSL::AST::MakeArrayReferenceExpression::MakeArrayReferenceExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLMakePointerExpression.h:
+        (WebCore::WHLSL::AST::MakePointerExpression::MakePointerExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLNamedType.h:
+        (WebCore::WHLSL::AST::NamedType::NamedType):
+        (WebCore::WHLSL::AST::NamedType::codeLocation const):
+        (WebCore::WHLSL::AST::NamedType::updateCodeLocation):
+        * Modules/webgpu/WHLSL/AST/WHLSLNativeTypeDeclaration.h:
+        (WebCore::WHLSL::AST::NativeTypeDeclaration::NativeTypeDeclaration):
+        * Modules/webgpu/WHLSL/AST/WHLSLNullLiteral.h:
+        (WebCore::WHLSL::AST::NullLiteral::NullLiteral):
+        (WebCore::WHLSL::AST::NullLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLNumThreadsFunctionAttribute.h:
+        (WebCore::WHLSL::AST::NumThreadsFunctionAttribute::NumThreadsFunctionAttribute):
+        * Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
+        (WebCore::WHLSL::AST::PointerType::PointerType):
+        * Modules/webgpu/WHLSL/AST/WHLSLPropertyAccessExpression.h:
+        (WebCore::WHLSL::AST::PropertyAccessExpression::PropertyAccessExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLReadModifyWriteExpression.h:
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::create):
+        (WebCore::WHLSL::AST::ReadModifyWriteExpression::ReadModifyWriteExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
+        (WebCore::WHLSL::AST::ReferenceType::ReferenceType):
+        * Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.h:
+        (WebCore::WHLSL::AST::ResourceSemantic::ResourceSemantic):
+        * Modules/webgpu/WHLSL/AST/WHLSLReturn.h:
+        (WebCore::WHLSL::AST::Return::Return):
+        * Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.h:
+        (WebCore::WHLSL::AST::SpecializationConstantSemantic::SpecializationConstantSemantic):
+        * Modules/webgpu/WHLSL/AST/WHLSLStageInOutSemantic.h:
+        (WebCore::WHLSL::AST::StageInOutSemantic::StageInOutSemantic):
+        * Modules/webgpu/WHLSL/AST/WHLSLStatement.h:
+        (WebCore::WHLSL::AST::Statement::Statement):
+        (WebCore::WHLSL::AST::Statement::codeLocation const):
+        (WebCore::WHLSL::AST::Statement::updateCodeLocation):
+        * Modules/webgpu/WHLSL/AST/WHLSLStatementList.h:
+        (WebCore::WHLSL::AST::StatementList::StatementList):
+        * Modules/webgpu/WHLSL/AST/WHLSLStructureDefinition.h:
+        (WebCore::WHLSL::AST::StructureDefinition::StructureDefinition):
+        * Modules/webgpu/WHLSL/AST/WHLSLStructureElement.h:
+        (WebCore::WHLSL::AST::StructureElement::StructureElement):
+        (WebCore::WHLSL::AST::StructureElement::codeLocation const):
+        * Modules/webgpu/WHLSL/AST/WHLSLSwitchCase.h:
+        (WebCore::WHLSL::AST::SwitchCase::SwitchCase):
+        * Modules/webgpu/WHLSL/AST/WHLSLSwitchStatement.h:
+        (WebCore::WHLSL::AST::SwitchStatement::SwitchStatement):
+        * Modules/webgpu/WHLSL/AST/WHLSLTernaryExpression.h:
+        (WebCore::WHLSL::AST::TernaryExpression::TernaryExpression):
+        * Modules/webgpu/WHLSL/AST/WHLSLTrap.h:
+        (WebCore::WHLSL::AST::Trap::Trap):
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeDefinition.h:
+        (WebCore::WHLSL::AST::TypeDefinition::TypeDefinition):
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeReference.cpp:
+        (WebCore::WHLSL::AST::TypeReference::wrap):
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
+        (WebCore::WHLSL::AST::TypeReference::TypeReference):
+        (WebCore::WHLSL::AST::TypeReference::cloneTypeReference const):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
+        (WebCore::WHLSL::AST::UnnamedType::UnnamedType):
+        (WebCore::WHLSL::AST::UnnamedType::codeLocation const):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteral.h:
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::UnsignedIntegerLiteral):
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteral::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.cpp:
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::UnsignedIntegerLiteralType):
+        (WebCore::WHLSL::AST::UnsignedIntegerLiteralType::clone const):
+        * Modules/webgpu/WHLSL/AST/WHLSLUnsignedIntegerLiteralType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLVariableDeclaration.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLVariableDeclarationsStatement.h:
+        (WebCore::WHLSL::AST::VariableDeclarationsStatement::VariableDeclarationsStatement):
+        * Modules/webgpu/WHLSL/AST/WHLSLVariableReference.h:
+        (WebCore::WHLSL::AST::VariableReference::VariableReference):
+        (WebCore::WHLSL::AST::VariableReference::wrap):
+        * Modules/webgpu/WHLSL/AST/WHLSLWhileLoop.h:
+        (WebCore::WHLSL::AST::WhileLoop::WhileLoop):
+        * Modules/webgpu/WHLSL/WHLSLAutoInitializeVariables.cpp:
+        (WebCore::WHLSL::AutoInitialize::visit):
+        * Modules/webgpu/WHLSL/WHLSLChecker.cpp:
+        (WebCore::WHLSL::resolveWithOperatorAnderIndexer):
+        (WebCore::WHLSL::resolveWithOperatorLength):
+        (WebCore::WHLSL::resolveWithReferenceComparator):
+        (WebCore::WHLSL::resolveByInstantiation):
+        (WebCore::WHLSL::resolveFunction):
+        (WebCore::WHLSL::Checker::visit):
+        (WebCore::WHLSL::argumentTypeForAndOverload):
+        (WebCore::WHLSL::Checker::finishVisiting):
+        * Modules/webgpu/WHLSL/WHLSLInferTypes.cpp:
+        (WebCore::WHLSL::matchAndCommit):
+        * Modules/webgpu/WHLSL/WHLSLLexer.cpp:
+        (WebCore::WHLSL::Token::typeName):
+        (WebCore::WHLSL::Lexer::consumeTokenFromStream):
+        * Modules/webgpu/WHLSL/WHLSLLexer.h:
+        (WebCore::WHLSL::AST::CodeLocation::CodeLocation):
+        (WebCore::WHLSL::AST::CodeLocation::startOffset const):
+        (WebCore::WHLSL::AST::CodeLocation::endOffset const):
+        (WebCore::WHLSL::Token::startOffset const):
+        (WebCore::WHLSL::Lexer::errorString):
+        (WebCore::WHLSL::Token::stringView const):
+        * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp:
+        (WebCore::WHLSL::NameResolver::visit):
+        * Modules/webgpu/WHLSL/WHLSLParser.cpp:
+        (WebCore::WHLSL::Parser::parse):
+        (WebCore::WHLSL::Parser::peek):
+        (WebCore::WHLSL::Parser::peekFurther):
+        (WebCore::WHLSL::Types::includes):
+        (WebCore::WHLSL::Types::appendNameTo):
+        (WebCore::WHLSL::Types<t>::includes):
+        (WebCore::WHLSL::Types<t>::appendNameTo):
+        (WebCore::WHLSL::Parser::peekType):
+        (WebCore::WHLSL::Parser::tryType):
+        (WebCore::WHLSL::Parser::tryTypes):
+        (WebCore::WHLSL::Parser::consumeType):
+        (WebCore::WHLSL::Parser::consumeTypes):
+        (WebCore::WHLSL::Parser::consumeIntegralLiteral):
+        (WebCore::WHLSL::Parser::parseConstantExpression):
+        (WebCore::WHLSL::Parser::parseTypeArgument):
+        (WebCore::WHLSL::Parser::parseTypeArguments):
+        (WebCore::WHLSL::Parser::parseTypeSuffixAbbreviated):
+        (WebCore::WHLSL::Parser::parseTypeSuffixNonAbbreviated):
+        (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::parseComputeFunctionDeclaration):
+        (WebCore::WHLSL::Parser::parseVertexOrFragmentFunctionDeclaration):
+        (WebCore::WHLSL::Parser::parseRegularFunctionDeclaration):
+        (WebCore::WHLSL::Parser::parseOperatorFunctionDeclaration):
+        (WebCore::WHLSL::Parser::parseFunctionDeclaration):
+        (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::parseLimitedSuffixOperator):
+        (WebCore::WHLSL::Parser::parseSuffixOperator):
+        (WebCore::WHLSL::Parser::parseExpression):
+        (WebCore::WHLSL::Parser::completeTernaryConditional):
+        (WebCore::WHLSL::Parser::completeAssignment):
+        (WebCore::WHLSL::Parser::parsePossibleTernaryConditional):
+        (WebCore::WHLSL::Parser::completePossibleLogicalBinaryOperation):
+        (WebCore::WHLSL::Parser::completePossibleRelationalBinaryOperation):
+        (WebCore::WHLSL::Parser::completePossibleShift):
+        (WebCore::WHLSL::Parser::completePossibleAdd):
+        (WebCore::WHLSL::Parser::completePossibleMultiply):
+        (WebCore::WHLSL::Parser::parsePossiblePrefix):
+        (WebCore::WHLSL::Parser::parsePossibleSuffix):
+        (WebCore::WHLSL::Parser::parseCallExpression):
+        (WebCore::WHLSL::Parser::parseTerm):
+        * Modules/webgpu/WHLSL/WHLSLParser.h:
+        * Modules/webgpu/WHLSL/WHLSLPreserveVariableLifetimes.cpp:
+        (WebCore::WHLSL::anonymousToken):
+        (WebCore::WHLSL::PreserveLifetimes::PreserveLifetimes):
+        (WebCore::WHLSL::PreserveLifetimes::assignVariableIntoStruct):
+        (WebCore::WHLSL::preserveVariableLifetimes):
+        * Modules/webgpu/WHLSL/WHLSLPropertyResolver.cpp:
+        (WebCore::WHLSL::PropertyResolver::visit):
+        (WebCore::WHLSL::wrapAnderCallArgument):
+        (WebCore::WHLSL::setterCall):
+        (WebCore::WHLSL::getterCall):
+        (WebCore::WHLSL::modify):
+        (WebCore::WHLSL::PropertyResolver::simplifyRightValue):
+        (WebCore::WHLSL::LeftValueSimplifier::finishVisiting):
+        * Modules/webgpu/WHLSL/WHLSLSynthesizeArrayOperatorLength.cpp:
+        (WebCore::WHLSL::synthesizeArrayOperatorLength):
+        * Modules/webgpu/WHLSL/WHLSLSynthesizeConstructors.cpp:
+        (WebCore::WHLSL::synthesizeConstructors):
+        * Modules/webgpu/WHLSL/WHLSLSynthesizeEnumerationFunctions.cpp:
+        (WebCore::WHLSL::synthesizeEnumerationFunctions):
+        * Modules/webgpu/WHLSL/WHLSLSynthesizeStructureAccessors.cpp:
+        (WebCore::WHLSL::synthesizeStructureAccessors):
+
 2019-07-10  Ryosuke Niwa  <rniwa@webkit.org>
 
         [iOS] REGRESSION(r244851): Revealing caret sometimes fails when content inset is used
index e36b8de..b40ae19 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 class ArrayReferenceType : public ReferenceType {
     using Base = ReferenceType;
 public:
-    ArrayReferenceType(Lexer::Token&& origin, AddressSpace addressSpace, UniqueRef<UnnamedType>&& elementType)
-        : Base(WTFMove(origin), addressSpace, WTFMove(elementType))
+    ArrayReferenceType(CodeLocation location, AddressSpace addressSpace, UniqueRef<UnnamedType>&& elementType)
+        : Base(location, addressSpace, WTFMove(elementType))
     {
     }
 
@@ -55,7 +55,7 @@ public:
 
     UniqueRef<UnnamedType> clone() const override
     {
-        return makeUniqueRef<ArrayReferenceType>(Lexer::Token(origin()), addressSpace(), elementType().clone());
+        return makeUniqueRef<ArrayReferenceType>(codeLocation(), addressSpace(), elementType().clone());
     }
 
     unsigned hash() const override
index 9e00c1a..41c5b35 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class ArrayType : public UnnamedType {
 public:
-    ArrayType(Lexer::Token&& origin, UniqueRef<UnnamedType>&& elementType, unsigned numElements)
-        : UnnamedType(WTFMove(origin))
+    ArrayType(CodeLocation location, UniqueRef<UnnamedType>&& elementType, unsigned numElements)
+        : UnnamedType(location)
         , m_elementType(WTFMove(elementType))
         , m_numElements(numElements)
     {
@@ -61,7 +61,7 @@ public:
 
     UniqueRef<UnnamedType> clone() const override
     {
-        return makeUniqueRef<ArrayType>(Lexer::Token(origin()), m_elementType->clone(), m_numElements);
+        return makeUniqueRef<ArrayType>(codeLocation(), m_elementType->clone(), m_numElements);
     }
 
     unsigned hash() const override
index 4b32cf0..05750c6 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class AssignmentExpression : public Expression {
 public:
-    AssignmentExpression(Lexer::Token&& origin, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
-        : Expression(WTFMove(origin))
+    AssignmentExpression(CodeLocation location, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
+        : Expression(location)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
     {
index 168990b..022b5ae 100644 (file)
@@ -37,8 +37,8 @@ namespace AST {
 
 class BaseFunctionAttribute {
 public:
-    BaseFunctionAttribute(Lexer::Token&& origin)
-        : m_origin(WTFMove(origin))
+    BaseFunctionAttribute(CodeLocation location)
+        : m_codeLocation(location)
     {
     }
 
@@ -48,7 +48,7 @@ public:
     BaseFunctionAttribute(BaseFunctionAttribute&&) = default;
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
 };
 
 } // namespace AST
index 3a9a7ab..27b42ca 100644 (file)
@@ -44,8 +44,8 @@ class UnnamedType;
 
 class BaseSemantic {
 public:
-    BaseSemantic(Lexer::Token&& origin)
-        : m_origin(WTFMove(origin))
+    BaseSemantic(CodeLocation location)
+        : m_codeLocation(location)
     {
     }
 
@@ -63,7 +63,7 @@ public:
     virtual bool isAcceptableForShaderItemDirection(ShaderItemDirection, const Optional<EntryPointType>&) const = 0;
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
 };
 
 } // namespace AST
index e42a178..ab08e2b 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class Block : public Statement {
 public:
-    Block(Lexer::Token&& origin, Statements&& statements)
-        : Statement(WTFMove(origin))
+    Block(CodeLocation location, Statements&& statements)
+        : Statement(location)
         , m_statements(WTFMove(statements))
     {
     }
index a218ea8..2f00367 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class BooleanLiteral : public Expression {
 public:
-    BooleanLiteral(Lexer::Token&& origin, bool value)
-        : Expression(WTFMove(origin))
+    BooleanLiteral(CodeLocation location, bool value)
+        : Expression(location)
         , m_value(value)
     {
     }
@@ -58,7 +58,7 @@ public:
 
     BooleanLiteral clone() const
     {
-        BooleanLiteral result(Lexer::Token(origin()), m_value);
+        BooleanLiteral result(codeLocation(), m_value);
         copyTypeTo(result);
         return result;
     }
index 965c00f..93226d3 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class Break : public Statement {
 public:
-    Break(Lexer::Token&& origin)
-        : Statement(WTFMove(origin))
+    Break(CodeLocation location)
+        : Statement(location)
     {
     }
 
index 33f8535..ec09904 100644 (file)
@@ -56,8 +56,8 @@ public:
         SVGroupThreadID
     };
 
-    BuiltInSemantic(Lexer::Token&& origin, Variable variable, Optional<unsigned>&& targetIndex = WTF::nullopt)
-        : BaseSemantic(WTFMove(origin))
+    BuiltInSemantic(CodeLocation location, Variable variable, Optional<unsigned>&& targetIndex = WTF::nullopt)
+        : BaseSemantic(location)
         , m_variable(variable)
         , m_targetIndex(WTFMove(targetIndex))
     {
index e6c38ca..eff610c 100644 (file)
@@ -42,8 +42,8 @@ class NamedType;
 
 class CallExpression : public Expression {
 public:
-    CallExpression(Lexer::Token&& origin, String&& name, Vector<UniqueRef<Expression>>&& arguments)
-        : Expression(WTFMove(origin))
+    CallExpression(CodeLocation location, String&& name, Vector<UniqueRef<Expression>>&& arguments)
+        : Expression(location)
         , m_name(WTFMove(name))
         , m_arguments(WTFMove(arguments))
     {
index 9702c28..e83ee0d 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class CommaExpression : public Expression {
 public:
-    CommaExpression(Lexer::Token&& origin, Vector<UniqueRef<Expression>>&& list)
-        : Expression(WTFMove(origin))
+    CommaExpression(CodeLocation location, Vector<UniqueRef<Expression>>&& list)
+        : Expression(location)
         , m_list(WTFMove(list))
     {
     }
index db9e7b6..b4a593f 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class Continue : public Statement {
 public:
-    Continue(Lexer::Token&& origin)
-        : Statement(WTFMove(origin))
+    Continue(CodeLocation location)
+        : Statement(location)
     {
     }
 
index e12122e..53cc97c 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class DereferenceExpression : public Expression {
 public:
-    DereferenceExpression(Lexer::Token&& origin, UniqueRef<Expression>&& pointer)
-        : Expression(WTFMove(origin))
+    DereferenceExpression(CodeLocation location, UniqueRef<Expression>&& pointer)
+        : Expression(location)
         , m_pointer(WTFMove(pointer))
     {
     }
index 1d921f6..395c1ec 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class DoWhileLoop : public Statement {
 public:
-    DoWhileLoop(Lexer::Token&& origin, UniqueRef<Statement>&& body, UniqueRef<Expression>&& conditional)
-        : Statement(WTFMove(origin))
+    DoWhileLoop(CodeLocation location, UniqueRef<Statement>&& body, UniqueRef<Expression>&& conditional)
+        : Statement(location)
         , m_body(WTFMove(body))
         , m_conditional(WTFMove(conditional))
     {
index 3337fb9..d541494 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class DotExpression : public PropertyAccessExpression {
 public:
-    DotExpression(Lexer::Token&& origin, UniqueRef<Expression>&& base, String&& fieldName)
-        : PropertyAccessExpression(WTFMove(origin), WTFMove(base))
+    DotExpression(CodeLocation location, UniqueRef<Expression>&& base, String&& fieldName)
+        : PropertyAccessExpression(location, WTFMove(base))
         , m_fieldName(WTFMove(fieldName))
     {
     }
index 70aea4b..14555c5 100644 (file)
@@ -41,7 +41,7 @@ namespace AST {
 class EffectfulExpressionStatement : public Statement {
 public:
     EffectfulExpressionStatement(UniqueRef<Expression>&& effectfulExpression)
-        : Statement(Lexer::Token(effectfulExpression->origin()))
+        : Statement(effectfulExpression->codeLocation())
         , m_effectfulExpression(WTFMove(effectfulExpression))
     {
     }
index 91dc7ae..a9f4713 100644 (file)
@@ -46,8 +46,8 @@ namespace AST {
 
 class EnumerationDefinition : public NamedType {
 public:
-    EnumerationDefinition(Lexer::Token&& origin, String&& name, UniqueRef<UnnamedType>&& type)
-        : NamedType(WTFMove(origin), WTFMove(name))
+    EnumerationDefinition(CodeLocation location, String&& name, UniqueRef<UnnamedType>&& type)
+        : NamedType(location, WTFMove(name))
         , m_type(WTFMove(type))
     {
     }
index 467de95..8a1d33e 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class EnumerationMember {
 public:
-    EnumerationMember(Lexer::Token&& origin, String&& name, Optional<ConstantExpression>&& value = WTF::nullopt)
-        : m_origin(WTFMove(origin))
+    EnumerationMember(CodeLocation location, String&& name, Optional<ConstantExpression>&& value = WTF::nullopt)
+        : m_codeLocation(location)
         , m_name(WTFMove(name))
         , m_value(WTFMove(value))
     {
@@ -53,7 +53,7 @@ public:
     EnumerationMember(const EnumerationMember&) = delete;
     EnumerationMember(EnumerationMember&&) = default;
 
-    const Lexer::Token& origin() const { return m_origin; }
+    const CodeLocation& codeLocation() const { return m_codeLocation; }
     String name() { return m_name; }
     Optional<ConstantExpression>& value() { return m_value; }
 
@@ -64,7 +64,7 @@ public:
     }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     String m_name;
     Optional<ConstantExpression> m_value;
 };
index 5cebde4..e4f5c7b 100644 (file)
@@ -41,8 +41,8 @@ class EnumerationMember;
 
 class EnumerationMemberLiteral : public Expression {
 public:
-    EnumerationMemberLiteral(Lexer::Token&& origin, String&& left, String&& right)
-        : Expression(WTFMove(origin))
+    EnumerationMemberLiteral(CodeLocation location, String&& left, String&& right)
+        : Expression(location)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
     {
@@ -58,9 +58,9 @@ public:
 
     bool isEnumerationMemberLiteral() const override { return true; }
 
-    static EnumerationMemberLiteral wrap(Lexer::Token&& origin, String&& left, String&& right, EnumerationDefinition& enumerationDefinition, EnumerationMember& enumerationMember)
+    static EnumerationMemberLiteral wrap(CodeLocation location, String&& left, String&& right, EnumerationDefinition& enumerationDefinition, EnumerationMember& enumerationMember)
     {
-        EnumerationMemberLiteral result(WTFMove(origin), WTFMove(left), WTFMove(right));
+        EnumerationMemberLiteral result(location, WTFMove(left), WTFMove(right));
         result.m_enumerationDefinition = &enumerationDefinition;
         result.m_enumerationMember = &enumerationMember;
         return result;
@@ -71,7 +71,7 @@ public:
 
     EnumerationMemberLiteral clone() const
     {
-        auto result = EnumerationMemberLiteral(Lexer::Token(origin()), String(m_left), String(m_right));
+        auto result = EnumerationMemberLiteral(codeLocation(), String(m_left), String(m_right));
         result.m_enumerationMember = m_enumerationMember;
         copyTypeTo(result);
         return result;
index b7ccc44..6a54dc4 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class Expression {
 public:
-    Expression(Lexer::Token&& origin)
-        : m_origin(WTFMove(origin))
+    Expression(CodeLocation codeLocation)
+        : m_codeLocation(codeLocation)
     {
     }
 
@@ -112,10 +112,11 @@ public:
     virtual bool isVariableReference() const { return false; }
     virtual bool isEnumerationMemberLiteral() const { return false; }
 
-    Lexer::Token origin() const { return m_origin; }
+    CodeLocation codeLocation() const { return m_codeLocation; }
+    void updateCodeLocation(CodeLocation location) { m_codeLocation = location; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     Optional<UniqueRef<UnnamedType>> m_type;
     Optional<TypeAnnotation> m_typeAnnotation;
 };
index 36bcf41..c61e6e2 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class Fallthrough : public Statement {
 public:
-    Fallthrough(Lexer::Token&& origin)
-        : Statement(WTFMove(origin))
+    Fallthrough(CodeLocation location)
+        : Statement(location)
     {
     }
 
index 93ece64..d8e7a5a 100644 (file)
@@ -39,9 +39,9 @@ namespace AST {
 
 class FloatLiteral : public Expression {
 public:
-    FloatLiteral(Lexer::Token&& origin, float value)
-        : Expression(Lexer::Token(origin))
-        , m_type(WTFMove(origin), value)
+    FloatLiteral(CodeLocation location, float value)
+        : Expression(location)
+        , m_type(location, value)
         , m_value(value)
     {
     }
@@ -61,7 +61,7 @@ public:
 
     FloatLiteral clone() const
     {
-        FloatLiteral result(Lexer::Token(origin()), m_value);
+        FloatLiteral result(codeLocation(), m_value);
         result.m_type = m_type.clone();
         if (auto* resolvedType = m_type.maybeResolvedType())
             result.m_type.resolve(resolvedType->clone());
index 8f90a75..a805d9c 100644 (file)
@@ -38,9 +38,9 @@ namespace WHLSL {
 
 namespace AST {
 
-FloatLiteralType::FloatLiteralType(Lexer::Token&& origin, float value)
+FloatLiteralType::FloatLiteralType(CodeLocation location, float value)
     : m_value(value)
-    , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "float"_str, TypeArguments()))
+    , m_preferredType(makeUniqueRef<TypeReference>(location, "float"_str, TypeArguments()))
 {
 }
 
@@ -74,7 +74,7 @@ unsigned FloatLiteralType::conversionCost(const UnnamedType& unnamedType) const
 
 FloatLiteralType FloatLiteralType::clone() const
 {
-    FloatLiteralType result(Lexer::Token(m_preferredType->origin()), m_value);
+    FloatLiteralType result(m_preferredType->codeLocation(), m_value);
     if (auto* type = maybeResolvedType())
         result.resolve(type->clone());
     result.m_preferredType = m_preferredType->cloneTypeReference();
index 1af3ce9..846495e 100644 (file)
@@ -41,7 +41,7 @@ class TypeReference;
 
 class FloatLiteralType : public ResolvableType {
 public:
-    FloatLiteralType(Lexer::Token&& origin, float value);
+    FloatLiteralType(CodeLocation, float value);
 
     virtual ~FloatLiteralType();
 
index 38679b2..d782397 100644 (file)
@@ -44,8 +44,8 @@ namespace AST {
 
 class ForLoop : public Statement {
 public:
-    ForLoop(Lexer::Token&& origin, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, Optional<UniqueRef<Expression>>&& condition, Optional<UniqueRef<Expression>>&& increment, UniqueRef<Statement>&& body)
-        : Statement(WTFMove(origin))
+    ForLoop(CodeLocation location, Variant<UniqueRef<Statement>, UniqueRef<Expression>>&& initialization, Optional<UniqueRef<Expression>>&& condition, Optional<UniqueRef<Expression>>&& increment, UniqueRef<Statement>&& body)
+        : Statement(location)
         , m_initialization(WTFMove(initialization))
         , m_condition(WTFMove(condition))
         , m_increment(WTFMove(increment))
index e1b05d4..58ddc93 100644 (file)
@@ -44,8 +44,8 @@ namespace AST {
 
 class FunctionDeclaration {
 public:
-    FunctionDeclaration(Lexer::Token&& origin, AttributeBlock&& attributeBlock, Optional<EntryPointType> entryPointType, UniqueRef<UnnamedType>&& type, String&& name, VariableDeclarations&& parameters, std::unique_ptr<Semantic>&& semantic, bool isOperator)
-        : m_origin(WTFMove(origin))
+    FunctionDeclaration(CodeLocation location, AttributeBlock&& attributeBlock, Optional<EntryPointType> entryPointType, UniqueRef<UnnamedType>&& type, String&& name, VariableDeclarations&& parameters, std::unique_ptr<Semantic>&& semantic, bool isOperator)
+        : m_codeLocation(location)
         , m_attributeBlock(WTFMove(attributeBlock))
         , m_entryPointType(entryPointType)
         , m_isOperator(WTFMove(isOperator))
@@ -75,10 +75,10 @@ public:
     VariableDeclarations& parameters() { return m_parameters; }
     Semantic* semantic() { return m_semantic.get(); }
     bool isOperator() const { return m_isOperator; }
-    Lexer::Token origin() { return m_origin; }
+    const CodeLocation& codeLocation() const { return m_codeLocation; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     AttributeBlock m_attributeBlock;
     Optional<EntryPointType> m_entryPointType;
     bool m_isOperator;
index b2b5f48..b1782f8 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class GlobalVariableReference : public Expression {
 public:
-    GlobalVariableReference(Lexer::Token&& origin, UniqueRef<Expression>&& base, StructureElement* structField)
-        : Expression(WTFMove(origin))
+    GlobalVariableReference(CodeLocation location, UniqueRef<Expression>&& base, StructureElement* structField)
+        : Expression(location)
         , m_base(WTFMove(base))
         , m_structField(*structField)
     {
index bf6f656..df7ab09 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class IfStatement : public Statement {
 public:
-    IfStatement(Lexer::Token&& origin, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body, Optional<UniqueRef<Statement>>&& elseBody)
-        : Statement(WTFMove(origin))
+    IfStatement(CodeLocation location, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body, Optional<UniqueRef<Statement>>&& elseBody)
+        : Statement(location)
         , m_conditional(WTFMove(conditional))
         , m_body(WTFMove(body))
         , m_elseBody(WTFMove(elseBody))
index 5e49116..5b1f15d 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class IndexExpression : public PropertyAccessExpression {
 public:
-    IndexExpression(Lexer::Token&& origin, UniqueRef<Expression>&& base, UniqueRef<Expression>&& index)
-        : PropertyAccessExpression(WTFMove(origin), WTFMove(base))
+    IndexExpression(CodeLocation location, UniqueRef<Expression>&& base, UniqueRef<Expression>&& index)
+        : PropertyAccessExpression(location, WTFMove(base))
         , m_index(WTFMove(index))
     {
     }
index f70344c..9131c8c 100644 (file)
@@ -39,9 +39,9 @@ namespace AST {
 
 class IntegerLiteral : public Expression {
 public:
-    IntegerLiteral(Lexer::Token&& origin, int value)
-        : Expression(Lexer::Token(origin))
-        , m_type(WTFMove(origin), value)
+    IntegerLiteral(CodeLocation location, int value)
+        : Expression(location)
+        , m_type(location, value)
         , m_value(value)
     {
     }
@@ -61,7 +61,7 @@ public:
 
     IntegerLiteral clone() const
     {
-        IntegerLiteral result(Lexer::Token(origin()), m_value);
+        IntegerLiteral result(codeLocation(), m_value);
         result.m_type = m_type.clone();
         if (auto* resolvedType = m_type.maybeResolvedType())
             result.m_type.resolve(resolvedType->clone());
index 91a8552..38161c2 100644 (file)
@@ -39,9 +39,9 @@ namespace WHLSL {
 
 namespace AST {
 
-IntegerLiteralType::IntegerLiteralType(Lexer::Token&& origin, int value)
+IntegerLiteralType::IntegerLiteralType(CodeLocation location, int value)
     : m_value(value)
-    , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "int"_str, TypeArguments()))
+    , m_preferredType(makeUniqueRef<TypeReference>(location, "int"_str, TypeArguments()))
 {
 }
 
@@ -75,7 +75,7 @@ unsigned IntegerLiteralType::conversionCost(const UnnamedType& unnamedType) cons
 
 IntegerLiteralType IntegerLiteralType::clone() const
 {
-    IntegerLiteralType result(Lexer::Token(m_preferredType->origin()), m_value);
+    IntegerLiteralType result(m_preferredType->codeLocation(), m_value);
     if (auto* type = maybeResolvedType())
         result.resolve(type->clone());
     result.m_preferredType = m_preferredType->cloneTypeReference();
index c510a81..c402676 100644 (file)
@@ -41,7 +41,7 @@ class TypeReference;
 
 class IntegerLiteralType : public ResolvableType {
 public:
-    IntegerLiteralType(Lexer::Token&& origin, int value);
+    IntegerLiteralType(CodeLocation, int value);
 
     virtual ~IntegerLiteralType();
 
index fbfc935..9be802a 100644 (file)
@@ -44,8 +44,8 @@ public:
         Or
     };
 
-    LogicalExpression(Lexer::Token&& origin, Type type, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
-        : Expression(WTFMove(origin))
+    LogicalExpression(CodeLocation location, Type type, UniqueRef<Expression>&& left, UniqueRef<Expression>&& right)
+        : Expression(location)
         , m_type(type)
         , m_left(WTFMove(left))
         , m_right(WTFMove(right))
index 1497632..6dab9b1 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class LogicalNotExpression : public Expression {
 public:
-    LogicalNotExpression(Lexer::Token&& origin, UniqueRef<Expression>&& operand)
-        : Expression(WTFMove(origin))
+    LogicalNotExpression(CodeLocation location, UniqueRef<Expression>&& operand)
+        : Expression(location)
         , m_operand(WTFMove(operand))
     {
     }
index 770cf8b..f778205 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class MakeArrayReferenceExpression : public Expression {
 public:
-    MakeArrayReferenceExpression(Lexer::Token&& origin, UniqueRef<Expression>&& leftValue)
-        : Expression(WTFMove(origin))
+    MakeArrayReferenceExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
+        : Expression(location)
         , m_leftValue(WTFMove(leftValue))
     {
     }
index 34604d5..5788da0 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class MakePointerExpression : public Expression {
 public:
-    MakePointerExpression(Lexer::Token&& origin, UniqueRef<Expression>&& leftValue)
-        : Expression(WTFMove(origin))
+    MakePointerExpression(CodeLocation location, UniqueRef<Expression>&& leftValue)
+        : Expression(location)
         , m_leftValue(WTFMove(leftValue))
     {
     }
index 22a61ba..193c594 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class NamedType : public Type {
 public:
-    NamedType(Lexer::Token&& origin, String&& name)
-        : m_origin(WTFMove(origin))
+    NamedType(CodeLocation location, String&& name)
+        : m_codeLocation(location)
         , m_name(WTFMove(name))
     {
     }
@@ -50,7 +50,9 @@ public:
     NamedType(const NamedType&) = delete;
     NamedType(NamedType&&) = default;
 
-    const Lexer::Token& origin() const { return m_origin; }
+    CodeLocation codeLocation() const { return m_codeLocation; }
+    void updateCodeLocation(CodeLocation location) { m_codeLocation = location; }
+
     String& name() { return m_name; }
 
     bool isNamedType() const override { return true; }
@@ -63,7 +65,7 @@ public:
     virtual Type& unifyNode() { return *this; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     String m_name;
 };
 
index 72e0204..2a218df 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class NativeTypeDeclaration : public NamedType {
 public:
-    NativeTypeDeclaration(Lexer::Token&& origin, String&& name, TypeArguments&& typeArguments)
-        : NamedType(WTFMove(origin), WTFMove(name))
+    NativeTypeDeclaration(CodeLocation location, String&& name, TypeArguments&& typeArguments)
+        : NamedType(location, WTFMove(name))
         , m_typeArguments(WTFMove(typeArguments))
     {
     }
index 84a1c3d..a411b2e 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class NullLiteral : public Expression {
 public:
-    NullLiteral(Lexer::Token&& origin)
-        : Expression(WTFMove(origin))
+    NullLiteral(CodeLocation location)
+        : Expression(location)
     {
     }
 
@@ -58,7 +58,7 @@ public:
 
     NullLiteral clone() const
     {
-        auto result = NullLiteral(Lexer::Token(origin()));
+        auto result = NullLiteral(codeLocation());
         if (auto* resolvedType = m_type.maybeResolvedType())
             result.m_type.resolve(resolvedType->clone());
         copyTypeTo(result);
index 38e298f..f5a1d26 100644 (file)
@@ -37,8 +37,8 @@ namespace AST {
 
 class NumThreadsFunctionAttribute : public BaseFunctionAttribute {
 public:
-    NumThreadsFunctionAttribute(Lexer::Token&& origin, unsigned width, unsigned height, unsigned depth)
-        : BaseFunctionAttribute(WTFMove(origin))
+    NumThreadsFunctionAttribute(CodeLocation location, unsigned width, unsigned height, unsigned depth)
+        : BaseFunctionAttribute(location)
         , m_width(width)
         , m_height(height)
         , m_depth(depth)
index 68e6d39..3a42401 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 class PointerType : public ReferenceType {
     using Base = ReferenceType;
 public:
-    PointerType(Lexer::Token&& origin, AddressSpace addressSpace, UniqueRef<UnnamedType> elementType)
-        : Base(WTFMove(origin), addressSpace, WTFMove(elementType))
+    PointerType(CodeLocation location, AddressSpace addressSpace, UniqueRef<UnnamedType> elementType)
+        : Base(location, addressSpace, WTFMove(elementType))
     {
     }
 
@@ -55,7 +55,7 @@ public:
 
     UniqueRef<UnnamedType> clone() const override
     {
-        return makeUniqueRef<PointerType>(Lexer::Token(origin()), addressSpace(), elementType().clone());
+        return makeUniqueRef<PointerType>(codeLocation(), addressSpace(), elementType().clone());
     }
 
     unsigned hash() const override
index 34d12a1..11ae9a8 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class PropertyAccessExpression : public Expression {
 public:
-    PropertyAccessExpression(Lexer::Token&& origin, UniqueRef<Expression>&& base)
-        : Expression(WTFMove(origin))
+    PropertyAccessExpression(CodeLocation location, UniqueRef<Expression>&& base)
+        : Expression(location)
         , m_base(WTFMove(base))
     {
     }
index 17e109a..a4837f0 100644 (file)
@@ -51,9 +51,9 @@ namespace AST {
  */
 class ReadModifyWriteExpression : public Expression {
 public:
-    static UniqueRef<ReadModifyWriteExpression> create(Lexer::Token&& origin, UniqueRef<Expression> lValue)
+    static UniqueRef<ReadModifyWriteExpression> create(CodeLocation location, UniqueRef<Expression> lValue)
     {
-        return makeUniqueRef<ReadModifyWriteExpression>(WTFMove(origin), WTFMove(lValue));
+        return makeUniqueRef<ReadModifyWriteExpression>(location, WTFMove(lValue));
     }
 
     virtual ~ReadModifyWriteExpression() = default;
@@ -115,11 +115,11 @@ public:
 private:
     template<class U, class... Args> friend UniqueRef<U> WTF::makeUniqueRef(Args&&...);
 
-    ReadModifyWriteExpression(Lexer::Token&& origin, UniqueRef<Expression> leftValue)
-        : Expression(Lexer::Token(origin))
+    ReadModifyWriteExpression(CodeLocation location, UniqueRef<Expression> leftValue)
+        : Expression(location)
         , m_leftValue(WTFMove(leftValue))
-        , m_oldValue(makeUniqueRef<VariableDeclaration>(Lexer::Token(origin), Qualifiers(), WTF::nullopt, String(), nullptr, nullptr))
-        , m_newValue(makeUniqueRef<VariableDeclaration>(WTFMove(origin), Qualifiers(), WTF::nullopt, String(), nullptr, nullptr))
+        , m_oldValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), WTF::nullopt, String(), nullptr, nullptr))
+        , m_newValue(makeUniqueRef<VariableDeclaration>(location, Qualifiers(), WTF::nullopt, String(), nullptr, nullptr))
     {
     }
 
index 0cff9ff..d56e95f 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class ReferenceType : public UnnamedType {
 public:
-    ReferenceType(Lexer::Token&& origin, AddressSpace addressSpace, UniqueRef<UnnamedType>&& elementType)
-        : UnnamedType(WTFMove(origin))
+    ReferenceType(CodeLocation location, AddressSpace addressSpace, UniqueRef<UnnamedType>&& elementType)
+        : UnnamedType(location)
         , m_addressSpace(addressSpace)
         , m_elementType(WTFMove(elementType))
     {
index cbff86b..d09b312 100644 (file)
@@ -45,8 +45,8 @@ public:
         Sampler
     };
 
-    ResourceSemantic(Lexer::Token&& origin, Mode mode, unsigned index, unsigned space)
-        : BaseSemantic(WTFMove(origin))
+    ResourceSemantic(CodeLocation location, Mode mode, unsigned index, unsigned space)
+        : BaseSemantic(location)
         , m_mode(mode)
         , m_index(index)
         , m_space(space)
index 75ace01..f46808c 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class Return : public Statement {
 public:
-    Return(Lexer::Token&& origin, Optional<UniqueRef<Expression>>&& value)
-        : Statement(WTFMove(origin))
+    Return(CodeLocation location, Optional<UniqueRef<Expression>>&& value)
+        : Statement(location)
         , m_value(WTFMove(value))
     {
     }
index 656315a..6b01f5e 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class SpecializationConstantSemantic : public BaseSemantic {
 public:
-    SpecializationConstantSemantic(Lexer::Token&& origin)
-        : BaseSemantic(WTFMove(origin))
+    SpecializationConstantSemantic(CodeLocation location)
+        : BaseSemantic(location)
     {
     }
 
index 61764c9..1d2b054 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class StageInOutSemantic : public BaseSemantic {
 public:
-    StageInOutSemantic(Lexer::Token&& origin, unsigned index)
-        : BaseSemantic(WTFMove(origin))
+    StageInOutSemantic(CodeLocation location, unsigned index)
+        : BaseSemantic(location)
         , m_index(index)
     {
     }
index 0c24566..278ad2b 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class Statement {
 public:
-    Statement(Lexer::Token&& origin)
-        : m_origin(WTFMove(origin))
+    Statement(CodeLocation codeLocation)
+        : m_codeLocation(codeLocation)
     {
     }
 
@@ -64,10 +64,11 @@ public:
     virtual bool isVariableDeclarationsStatement() const { return false; }
     virtual bool isWhileLoop() const { return false; }
 
-    Lexer::Token origin() const { return m_origin; }
+    CodeLocation codeLocation() const { return m_codeLocation; }
+    void updateCodeLocation(CodeLocation location) { m_codeLocation = location; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
 };
 
 using Statements = Vector<UniqueRef<Statement>>;
index 3ec6f42..ddaca53 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 class StatementList : public Statement {
     using Base = Statement;
 public:
-    StatementList(Lexer::Token&& origin, Statements&& statements)
-        : Base(WTFMove(origin))
+    StatementList(CodeLocation location, Statements&& statements)
+        : Base(location)
         , m_statements(WTFMove(statements))
     { }
 
index c97bad0..433f934 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class StructureDefinition : public NamedType {
 public:
-    StructureDefinition(Lexer::Token&& origin, String&& name, StructureElements&& structureElements)
-        : NamedType(WTFMove(origin), WTFMove(name))
+    StructureDefinition(CodeLocation location, String&& name, StructureElements&& structureElements)
+        : NamedType(location, WTFMove(name))
         , m_structureElements(WTFMove(structureElements))
     {
     }
index 0ae469c..cb91b57 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class StructureElement {
 public:
-    StructureElement(Lexer::Token&& origin, Qualifiers&& qualifiers, UniqueRef<UnnamedType>&& type, String&& name, std::unique_ptr<Semantic>&& semantic)
-        : m_origin(WTFMove(origin))
+    StructureElement(CodeLocation location, Qualifiers&& qualifiers, UniqueRef<UnnamedType>&& type, String&& name, std::unique_ptr<Semantic>&& semantic)
+        : m_codeLocation(location)
         , m_qualifiers(WTFMove(qualifiers))
         , m_type(WTFMove(type))
         , m_name(WTFMove(name))
@@ -55,13 +55,13 @@ public:
     StructureElement(const StructureElement&) = delete;
     StructureElement(StructureElement&&) = default;
 
-    const Lexer::Token& origin() const { return m_origin; }
+    const CodeLocation& codeLocation() const { return m_codeLocation; }
     UnnamedType& type() { return m_type; }
     const String& name() { return m_name; }
     Semantic* semantic() { return m_semantic.get(); }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     Qualifiers m_qualifiers;
     UniqueRef<UnnamedType> m_type;
     String m_name;
index fe9f8a8..ef383f9 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class SwitchCase : public Statement {
 public:
-    SwitchCase(Lexer::Token&& origin, Optional<ConstantExpression>&& value, Block&& block)
-        : Statement(WTFMove(origin))
+    SwitchCase(CodeLocation location, Optional<ConstantExpression>&& value, Block&& block)
+        : Statement(location)
         , m_value(WTFMove(value))
         , m_block(WTFMove(block))
     {
index 7c160ba..8c008bb 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class SwitchStatement : public Statement {
 public:
-    SwitchStatement(Lexer::Token&& origin, UniqueRef<Expression>&& value, Vector<SwitchCase>&& switchCases)
-        : Statement(WTFMove(origin))
+    SwitchStatement(CodeLocation location, UniqueRef<Expression>&& value, Vector<SwitchCase>&& switchCases)
+        : Statement(location)
         , m_value(WTFMove(value))
         , m_switchCases(WTFMove(switchCases))
     {
index fe5614d..7dc10a0 100644 (file)
@@ -39,8 +39,8 @@ namespace AST {
 
 class TernaryExpression : public Expression {
 public:
-    TernaryExpression(Lexer::Token&& origin, UniqueRef<Expression>&& predicate, UniqueRef<Expression>&& bodyExpression, UniqueRef<Expression>&& elseExpression)
-        : Expression(WTFMove(origin))
+    TernaryExpression(CodeLocation location, UniqueRef<Expression>&& predicate, UniqueRef<Expression>&& bodyExpression, UniqueRef<Expression>&& elseExpression)
+        : Expression(location)
         , m_predicate(WTFMove(predicate))
         , m_bodyExpression(WTFMove(bodyExpression))
         , m_elseExpression(WTFMove(elseExpression))
index d280e71..4a4717f 100644 (file)
@@ -38,8 +38,8 @@ namespace AST {
 
 class Trap : public Statement {
 public:
-    Trap(Lexer::Token&& origin)
-        : Statement(WTFMove(origin))
+    Trap(CodeLocation location)
+        : Statement(location)
     {
     }
 
index 88688ac..8e0f960 100644 (file)
@@ -41,8 +41,8 @@ namespace AST {
 
 class TypeDefinition : public NamedType {
 public:
-    TypeDefinition(Lexer::Token&& origin, String&& name, UniqueRef<UnnamedType>&& type)
-        : NamedType(WTFMove(origin), WTFMove(name))
+    TypeDefinition(CodeLocation location, String&& name, UniqueRef<UnnamedType>&& type)
+        : NamedType(location, WTFMove(name))
         , m_type(WTFMove(type))
     {
     }
index a2d8fe4..c3d1b5e 100644 (file)
@@ -37,12 +37,12 @@ namespace WHLSL {
 
 namespace AST {
 
-UniqueRef<TypeReference> TypeReference::wrap(Lexer::Token&& origin, NamedType& resolvedType)
+UniqueRef<TypeReference> TypeReference::wrap(CodeLocation location, NamedType& resolvedType)
 {
     TypeArguments typeArguments;
     if (is<NativeTypeDeclaration>(resolvedType))
         typeArguments = AST::clone(downcast<NativeTypeDeclaration>(resolvedType).typeArguments());
-    auto result = makeUniqueRef<TypeReference>(WTFMove(origin), String(resolvedType.name()), WTFMove(typeArguments));
+    auto result = makeUniqueRef<TypeReference>(location, String(resolvedType.name()), WTFMove(typeArguments));
     result->setResolvedType(resolvedType);
     return result;
 }
index 46ba05e..04cb432 100644 (file)
@@ -44,8 +44,8 @@ class NamedType;
 
 class TypeReference : public UnnamedType {
 public:
-    TypeReference(Lexer::Token&& origin, String&& name, TypeArguments&& typeArguments)
-        : UnnamedType(WTFMove(origin))
+    TypeReference(CodeLocation location, String&& name, TypeArguments&& typeArguments)
+        : UnnamedType(location)
         , m_name(WTFMove(name))
         , m_typeArguments(WTFMove(typeArguments))
     {
@@ -56,7 +56,7 @@ public:
     TypeReference(const TypeReference&) = delete;
     TypeReference(TypeReference&&) = default;
 
-    static UniqueRef<TypeReference> wrap(Lexer::Token&& origin, NamedType& resolvedType);
+    static UniqueRef<TypeReference> wrap(CodeLocation, NamedType& resolvedType);
 
     bool isTypeReference() const override { return true; }
 
@@ -88,7 +88,7 @@ public:
 
     UniqueRef<TypeReference> cloneTypeReference() const
     {
-        auto result = makeUniqueRef<TypeReference>(Lexer::Token(origin()), String(m_name), AST::clone(m_typeArguments));
+        auto result = makeUniqueRef<TypeReference>(codeLocation(), String(m_name), AST::clone(m_typeArguments));
         if (m_resolvedType)
             result->setResolvedType(*m_resolvedType);
         return result;
index 9071099..2577623 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class UnnamedType : public Type {
 public:
-    UnnamedType(Lexer::Token&& origin)
-        : m_origin(WTFMove(origin))
+    UnnamedType(CodeLocation location)
+        : m_codeLocation(location)
     {
     }
 
@@ -65,10 +65,10 @@ public:
     virtual unsigned hash() const = 0;
     virtual bool operator==(const UnnamedType&) const = 0;
 
-    const Lexer::Token& origin() const { return m_origin; }
+    const CodeLocation& codeLocation() const { return m_codeLocation; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
 };
 
 } // namespace AST
index 9ea5862..452e661 100644 (file)
@@ -39,9 +39,9 @@ namespace AST {
 
 class UnsignedIntegerLiteral : public Expression {
 public:
-    UnsignedIntegerLiteral(Lexer::Token&& origin, unsigned value)
-        : Expression(Lexer::Token(origin))
-        , m_type(WTFMove(origin), value)
+    UnsignedIntegerLiteral(CodeLocation location, unsigned value)
+        : Expression(location)
+        , m_type(location, value)
         , m_value(value)
     {
     }
@@ -61,7 +61,7 @@ public:
 
     UnsignedIntegerLiteral clone() const
     {
-        UnsignedIntegerLiteral result(Lexer::Token(origin()), m_value);
+        UnsignedIntegerLiteral result(codeLocation(), m_value);
         result.m_type = m_type.clone();
         if (auto* resolvedType = m_type.maybeResolvedType())
             result.m_type.resolve(resolvedType->clone());
index 77218b0..462b35f 100644 (file)
@@ -40,9 +40,9 @@ namespace WHLSL {
 
 namespace AST {
 
-UnsignedIntegerLiteralType::UnsignedIntegerLiteralType(Lexer::Token&& origin, unsigned value)
+UnsignedIntegerLiteralType::UnsignedIntegerLiteralType(CodeLocation location, unsigned value)
     : m_value(value)
-    , m_preferredType(makeUniqueRef<TypeReference>(WTFMove(origin), "uint"_str, TypeArguments()))
+    , m_preferredType(makeUniqueRef<TypeReference>(location, "uint"_str, TypeArguments()))
 {
 }
 
@@ -78,7 +78,7 @@ unsigned UnsignedIntegerLiteralType::conversionCost(const UnnamedType& unnamedTy
 
 UnsignedIntegerLiteralType UnsignedIntegerLiteralType::clone() const
 {
-    UnsignedIntegerLiteralType result(Lexer::Token(m_preferredType->origin()), m_value);
+    UnsignedIntegerLiteralType result(m_preferredType->codeLocation(), m_value);
     if (auto* type = maybeResolvedType())
         result.resolve(type->clone());
     result.m_preferredType = m_preferredType->cloneTypeReference();
index 93058de..cdb28c0 100644 (file)
@@ -41,7 +41,7 @@ class TypeReference;
 
 class UnsignedIntegerLiteralType : public ResolvableType {
 public:
-    UnsignedIntegerLiteralType(Lexer::Token&& origin, unsigned value);
+    UnsignedIntegerLiteralType(CodeLocation, unsigned value);
 
     virtual ~UnsignedIntegerLiteralType();
 
index c0dc8d4..eafc490 100644 (file)
@@ -46,8 +46,8 @@ namespace AST {
 class VariableDeclaration final {
 // Final because we made the destructor non-virtual.
 public:
-    VariableDeclaration(Lexer::Token&& origin, Qualifiers&& qualifiers, Optional<UniqueRef<UnnamedType>>&& type, String&& name, std::unique_ptr<Semantic>&& semantic, std::unique_ptr<Expression>&& initializer)
-        : m_origin(WTFMove(origin))
+    VariableDeclaration(CodeLocation codeLocation, Qualifiers&& qualifiers, Optional<UniqueRef<UnnamedType>>&& type, String&& name, std::unique_ptr<Semantic>&& semantic, std::unique_ptr<Expression>&& initializer)
+        : m_codeLocation(codeLocation)
         , m_qualifiers(WTFMove(qualifiers))
         , m_type(WTFMove(type))
         , m_name(WTFMove(name))
@@ -83,10 +83,10 @@ public:
         ASSERT(expression);
         m_initializer = WTFMove(expression);
     }
-    Lexer::Token origin() const { return m_origin; }
+    CodeLocation codeLocation() const { return m_codeLocation; }
 
 private:
-    Lexer::Token m_origin;
+    CodeLocation m_codeLocation;
     Qualifiers m_qualifiers;
     Optional<UniqueRef<UnnamedType>> m_type;
     String m_name;
index 09a02d0..6cd53b3 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class VariableDeclarationsStatement : public Statement {
 public:
-    VariableDeclarationsStatement(Lexer::Token&& origin, VariableDeclarations&& variableDeclarations)
-        : Statement(WTFMove(origin))
+    VariableDeclarationsStatement(CodeLocation location, VariableDeclarations&& variableDeclarations)
+        : Statement(location)
         , m_variableDeclarations(WTFMove(variableDeclarations))
     {
     }
index ade40e7..f6bdeb0 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class VariableReference : public Expression {
 public:
-    VariableReference(Lexer::Token&& origin, String&& name)
-        : Expression(WTFMove(origin))
+    VariableReference(CodeLocation location, String&& name)
+        : Expression(location)
         , m_name(WTFMove(name))
     {
     }
@@ -53,7 +53,7 @@ public:
 
     static VariableReference wrap(VariableDeclaration& variableDeclaration)
     {
-        VariableReference result(Lexer::Token(variableDeclaration.origin()));
+        VariableReference result(variableDeclaration.codeLocation());
         result.m_variable = &variableDeclaration;
         result.m_name = variableDeclaration.name();
         return result;
@@ -71,8 +71,8 @@ public:
     }
 
 private:
-    VariableReference(Lexer::Token&& origin)
-        : Expression(WTFMove(origin))
+    VariableReference(CodeLocation location)
+        : Expression(location)
     {
     }
 
index a6c7b5e..55c0377 100644 (file)
@@ -40,8 +40,8 @@ namespace AST {
 
 class WhileLoop : public Statement {
 public:
-    WhileLoop(Lexer::Token&& origin, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body)
-        : Statement(WTFMove(origin))
+    WhileLoop(CodeLocation location, UniqueRef<Expression>&& conditional, UniqueRef<Statement>&& body)
+        : Statement(location)
         , m_conditional(WTFMove(conditional))
         , m_body(WTFMove(body))
     {
index 8164709..18fe0d2 100644 (file)
@@ -69,7 +69,7 @@ private:
 #else
         String functionName = "<zero-init>"_s;
 #endif
-        auto callExpression = std::make_unique<AST::CallExpression>(variableDeclaration.origin(), WTFMove(functionName), Vector<UniqueRef<AST::Expression>>());
+        auto callExpression = std::make_unique<AST::CallExpression>(variableDeclaration.codeLocation(), WTFMove(functionName), Vector<UniqueRef<AST::Expression>>());
         callExpression->setType(type->clone());
         callExpression->setTypeAnnotation(AST::RightValue());
         Vector<std::reference_wrapper<ResolvingType>> argumentTypes;
index d809414..c0c83ff 100644 (file)
@@ -118,29 +118,29 @@ public:
     }
 };
 
-static AST::NativeFunctionDeclaration resolveWithOperatorAnderIndexer(Lexer::Token origin, AST::ArrayReferenceType& firstArgument, const Intrinsics& intrinsics)
+static AST::NativeFunctionDeclaration resolveWithOperatorAnderIndexer(AST::CodeLocation location, AST::ArrayReferenceType& firstArgument, const Intrinsics& intrinsics)
 {
     const bool isOperator = true;
-    auto returnType = makeUniqueRef<AST::PointerType>(Lexer::Token(origin), firstArgument.addressSpace(), firstArgument.elementType().clone());
+    auto returnType = makeUniqueRef<AST::PointerType>(location, firstArgument.addressSpace(), firstArgument.elementType().clone());
     AST::VariableDeclarations parameters;
-    parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), firstArgument.clone(), String(), nullptr, nullptr));
-    parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.uintType())), String(), nullptr, nullptr));
-    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
+    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), firstArgument.clone(), String(), nullptr, nullptr));
+    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, intrinsics.uintType())), String(), nullptr, nullptr));
+    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator&[]", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
 }
 
-static AST::NativeFunctionDeclaration resolveWithOperatorLength(Lexer::Token origin, AST::UnnamedType& firstArgument, const Intrinsics& intrinsics)
+static AST::NativeFunctionDeclaration resolveWithOperatorLength(AST::CodeLocation location, AST::UnnamedType& firstArgument, const Intrinsics& intrinsics)
 {
     const bool isOperator = true;
-    auto returnType = AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.uintType());
+    auto returnType = AST::TypeReference::wrap(location, intrinsics.uintType());
     AST::VariableDeclarations parameters;
-    parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), firstArgument.clone(), String(), nullptr, nullptr));
-    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
+    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), firstArgument.clone(), String(), nullptr, nullptr));
+    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator.length", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
 }
 
-static AST::NativeFunctionDeclaration resolveWithReferenceComparator(Lexer::Token origin, ResolvingType& firstArgument, ResolvingType& secondArgument, const Intrinsics& intrinsics)
+static AST::NativeFunctionDeclaration resolveWithReferenceComparator(AST::CodeLocation location, ResolvingType& firstArgument, ResolvingType& secondArgument, const Intrinsics& intrinsics)
 {
     const bool isOperator = true;
-    auto returnType = AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.boolType());
+    auto returnType = AST::TypeReference::wrap(location, intrinsics.boolType());
     auto argumentType = firstArgument.visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> UniqueRef<AST::UnnamedType> {
         return unnamedType->clone();
     }, [&](RefPtr<ResolvableTypeReference>&) -> UniqueRef<AST::UnnamedType> {
@@ -150,13 +150,13 @@ static AST::NativeFunctionDeclaration resolveWithReferenceComparator(Lexer::Toke
             // We encountered "null == null".
             // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198162 This can probably be generalized, using the "preferred type" infrastructure used by generic literals
             ASSERT_NOT_REACHED();
-            return AST::TypeReference::wrap(Lexer::Token(origin), intrinsics.intType());
+            return AST::TypeReference::wrap(location, intrinsics.intType());
         }));
     }));
     AST::VariableDeclarations parameters;
-    parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), argumentType->clone(), String(), nullptr, nullptr));
-    parameters.append(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), nullptr, nullptr));
-    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(origin), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
+    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), argumentType->clone(), String(), nullptr, nullptr));
+    parameters.append(makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), nullptr, nullptr));
+    return AST::NativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), String("operator==", String::ConstructFromLiteral), WTFMove(parameters), nullptr, isOperator));
 }
 
 enum class Acceptability {
@@ -165,7 +165,7 @@ enum class Acceptability {
     No
 };
 
-static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const String& name, Lexer::Token origin, const Vector<std::reference_wrapper<ResolvingType>>& types, const Intrinsics& intrinsics)
+static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const String& name, AST::CodeLocation location, const Vector<std::reference_wrapper<ResolvingType>>& types, const Intrinsics& intrinsics)
 {
     if (name == "operator&[]" && types.size() == 2) {
         auto* firstArgumentArrayRef = types[0].get().visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> AST::ArrayReferenceType* {
@@ -181,7 +181,7 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str
             return resolvableTypeReference->resolvableType().canResolve(intrinsics.uintType());
         }));
         if (firstArgumentArrayRef && secondArgumentIsUint)
-            return resolveWithOperatorAnderIndexer(origin, *firstArgumentArrayRef, intrinsics);
+            return resolveWithOperatorAnderIndexer(location, *firstArgumentArrayRef, intrinsics);
     } else if (name == "operator.length" && types.size() == 1) {
         auto* firstArgumentReference = types[0].get().visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> AST::UnnamedType* {
             if (is<AST::ArrayReferenceType>(static_cast<AST::UnnamedType&>(unnamedType)) || is<AST::ArrayType>(static_cast<AST::UnnamedType&>(unnamedType)))
@@ -191,7 +191,7 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str
             return nullptr;
         }));
         if (firstArgumentReference)
-            return resolveWithOperatorLength(origin, *firstArgumentReference, intrinsics);
+            return resolveWithOperatorLength(location, *firstArgumentReference, intrinsics);
     } else if (name == "operator==" && types.size() == 2) {
         auto acceptability = [](ResolvingType& resolvingType) -> Acceptability {
             return resolvingType.visit(WTF::makeVisitor([](UniqueRef<AST::UnnamedType>& unnamedType) -> Acceptability {
@@ -212,19 +212,19 @@ static Optional<AST::NativeFunctionDeclaration> resolveByInstantiation(const Str
             || (leftAcceptability == Acceptability::Yes && rightAcceptability == Acceptability::Maybe))
             success = true;
         if (success)
-            return resolveWithReferenceComparator(origin, types[0].get(), types[1].get(), intrinsics);
+            return resolveWithReferenceComparator(location, types[0].get(), types[1].get(), intrinsics);
     }
     return WTF::nullopt;
 }
 
-static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, Lexer::Token origin, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr)
+static AST::FunctionDeclaration* resolveFunction(Program& program, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* possibleOverloads, Vector<std::reference_wrapper<ResolvingType>>& types, const String& name, AST::CodeLocation location, const Intrinsics& intrinsics, AST::NamedType* castReturnType = nullptr)
 {
     if (possibleOverloads) {
         if (AST::FunctionDeclaration* function = resolveFunctionOverload(*possibleOverloads, types, castReturnType))
             return function;
     }
 
-    if (auto newFunction = resolveByInstantiation(name, origin, types, intrinsics)) {
+    if (auto newFunction = resolveByInstantiation(name, location, types, intrinsics)) {
         program.append(WTFMove(*newFunction));
         return &program.nativeFunctionDeclarations().last();
     }
@@ -703,10 +703,10 @@ void Checker::visit(AST::EnumerationDefinition& enumerationDefinition)
         } else {
             if (nextValue > std::numeric_limits<int>::max()) {
                 ASSERT(nextValue <= std::numeric_limits<unsigned>::max());
-                member.get().setValue(AST::ConstantExpression(AST::UnsignedIntegerLiteral(Lexer::Token(member.get().origin()), static_cast<unsigned>(nextValue))));
+                member.get().setValue(AST::ConstantExpression(AST::UnsignedIntegerLiteral(member.get().codeLocation(), static_cast<unsigned>(nextValue))));
             }
             ASSERT(nextValue >= std::numeric_limits<int>::min());
-            member.get().setValue(AST::ConstantExpression(AST::IntegerLiteral(Lexer::Token(member.get().origin()), static_cast<int>(nextValue))));
+            member.get().setValue(AST::ConstantExpression(AST::IntegerLiteral(member.get().codeLocation(), static_cast<int>(nextValue))));
 
             if (!matchAndCommitMember(member)) {
                 setError();
@@ -926,7 +926,7 @@ void Checker::visit(AST::MakePointerExpression& makePointerExpression)
         return;
     }
 
-    assignType(makePointerExpression, makeUniqueRef<AST::PointerType>(Lexer::Token(makePointerExpression.origin()), *leftAddressSpace, leftValueType->clone()));
+    assignType(makePointerExpression, makeUniqueRef<AST::PointerType>(makePointerExpression.codeLocation(), *leftAddressSpace, leftValueType->clone()));
 }
 
 void Checker::visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpression)
@@ -947,7 +947,7 @@ void Checker::visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpress
         if (is<AST::PointerType>(unnamedType)) {
             auto& pointerType = downcast<AST::PointerType>(unnamedType);
             // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198163 Save the fact that we're not targetting the item; we're targetting the item's inner element.
-            assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(makeArrayReferenceExpression.origin()), pointerType.addressSpace(), pointerType.elementType().clone()));
+            assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(makeArrayReferenceExpression.codeLocation(), pointerType.addressSpace(), pointerType.elementType().clone()));
             return;
         }
 
@@ -960,7 +960,7 @@ void Checker::visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpress
         if (is<AST::ArrayType>(unnamedType)) {
             auto& arrayType = downcast<AST::ArrayType>(unnamedType);
             // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198163 Save the number of elements.
-            assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(makeArrayReferenceExpression.origin()), *leftAddressSpace, arrayType.type().clone()));
+            assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(makeArrayReferenceExpression.codeLocation(), *leftAddressSpace, arrayType.type().clone()));
             return;
         }
     }
@@ -971,7 +971,7 @@ void Checker::visit(AST::MakeArrayReferenceExpression& makeArrayReferenceExpress
         return;
     }
 
-    assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(makeArrayReferenceExpression.origin()), *leftAddressSpace, leftValueType->clone()));
+    assignType(makeArrayReferenceExpression, makeUniqueRef<AST::ArrayReferenceType>(makeArrayReferenceExpression.codeLocation(), *leftAddressSpace, leftValueType->clone()));
 }
 
 static Optional<UniqueRef<AST::UnnamedType>> argumentTypeForAndOverload(AST::UnnamedType& baseType, AST::AddressSpace addressSpace)
@@ -979,7 +979,7 @@ static Optional<UniqueRef<AST::UnnamedType>> argumentTypeForAndOverload(AST::Unn
     auto& unifyNode = baseType.unifyNode();
     if (is<AST::NamedType>(unifyNode)) {
         auto& namedType = downcast<AST::NamedType>(unifyNode);
-        return { makeUniqueRef<AST::PointerType>(Lexer::Token(namedType.origin()), addressSpace, AST::TypeReference::wrap(Lexer::Token(namedType.origin()), namedType)) };
+        return { makeUniqueRef<AST::PointerType>(namedType.codeLocation(), addressSpace, AST::TypeReference::wrap(namedType.codeLocation(), namedType)) };
     }
 
     auto& unnamedType = downcast<AST::UnnamedType>(unifyNode);
@@ -988,12 +988,12 @@ static Optional<UniqueRef<AST::UnnamedType>> argumentTypeForAndOverload(AST::Unn
         return unnamedType.clone();
 
     if (is<AST::ArrayType>(unnamedType))
-        return { makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(unnamedType.origin()), addressSpace, downcast<AST::ArrayType>(unnamedType).type().clone()) };
+        return { makeUniqueRef<AST::ArrayReferenceType>(unnamedType.codeLocation(), addressSpace, downcast<AST::ArrayType>(unnamedType).type().clone()) };
 
     if (is<AST::PointerType>(unnamedType))
         return WTF::nullopt;
 
-    return { makeUniqueRef<AST::PointerType>(Lexer::Token(unnamedType.origin()), addressSpace, unnamedType.clone()) };
+    return { makeUniqueRef<AST::PointerType>(unnamedType.codeLocation(), addressSpace, unnamedType.clone()) };
 }
 
 void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpression, ResolvingType* additionalArgumentType)
@@ -1013,7 +1013,7 @@ void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpres
             getterArgumentTypes.append(*additionalArgumentType);
         auto getterName = propertyAccessExpression.getterFunctionName();
         auto* getterFunctions = m_program.nameContext().getFunctions(getterName);
-        getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.origin(), m_intrinsics);
+        getterFunction = resolveFunction(m_program, getterFunctions, getterArgumentTypes, getterName, propertyAccessExpression.codeLocation(), m_intrinsics);
         if (getterFunction)
             getterReturnType = &getterFunction->type();
     }
@@ -1029,7 +1029,7 @@ void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpres
                 anderArgumentTypes.append(*additionalArgumentType);
             auto anderName = propertyAccessExpression.anderFunctionName();
             auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
-            anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
+            anderFunction = resolveFunction(m_program, anderFunctions, anderArgumentTypes, anderName, propertyAccessExpression.codeLocation(), m_intrinsics);
             if (anderFunction)
                 anderReturnType = &downcast<AST::PointerType>(anderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer
         }
@@ -1038,13 +1038,13 @@ void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpres
     AST::FunctionDeclaration* threadAnderFunction = nullptr;
     AST::UnnamedType* threadAnderReturnType = nullptr;
     if (auto argumentTypeForAndOverload = WHLSL::argumentTypeForAndOverload(*baseUnnamedType, AST::AddressSpace::Thread)) {
-        ResolvingType argumentType = { makeUniqueRef<AST::PointerType>(Lexer::Token(propertyAccessExpression.origin()), AST::AddressSpace::Thread, baseUnnamedType->get().clone()) };
+        ResolvingType argumentType = { makeUniqueRef<AST::PointerType>(propertyAccessExpression.codeLocation(), AST::AddressSpace::Thread, baseUnnamedType->get().clone()) };
         Vector<std::reference_wrapper<ResolvingType>> threadAnderArgumentTypes { argumentType };
         if (additionalArgumentType)
             threadAnderArgumentTypes.append(*additionalArgumentType);
         auto anderName = propertyAccessExpression.anderFunctionName();
         auto* anderFunctions = m_program.nameContext().getFunctions(anderName);
-        threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.origin(), m_intrinsics);
+        threadAnderFunction = resolveFunction(m_program, anderFunctions, threadAnderArgumentTypes, anderName, propertyAccessExpression.codeLocation(), m_intrinsics);
         if (threadAnderFunction)
             threadAnderReturnType = &downcast<AST::PointerType>(threadAnderFunction->type()).elementType(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198164 Enforce the return of anders will always be a pointer
     }
@@ -1091,7 +1091,7 @@ void Checker::finishVisiting(AST::PropertyAccessExpression& propertyAccessExpres
         setterArgumentTypes.append(fieldResolvingType);
         auto setterName = propertyAccessExpression.setterFunctionName();
         auto* setterFunctions = m_program.nameContext().getFunctions(setterName);
-        setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.origin(), m_intrinsics);
+        setterFunction = resolveFunction(m_program, setterFunctions, setterArgumentTypes, setterName, propertyAccessExpression.codeLocation(), m_intrinsics);
         if (setterFunction)
             setterReturnType = &setterFunction->type();
     }
@@ -1189,14 +1189,14 @@ void Checker::visit(AST::NullLiteral& nullLiteral)
 
 void Checker::visit(AST::BooleanLiteral& booleanLiteral)
 {
-    assignType(booleanLiteral, AST::TypeReference::wrap(Lexer::Token(booleanLiteral.origin()), m_intrinsics.boolType()));
+    assignType(booleanLiteral, AST::TypeReference::wrap(booleanLiteral.codeLocation(), m_intrinsics.boolType()));
 }
 
 void Checker::visit(AST::EnumerationMemberLiteral& enumerationMemberLiteral)
 {
     ASSERT(enumerationMemberLiteral.enumerationDefinition());
     auto& enumerationDefinition = *enumerationMemberLiteral.enumerationDefinition();
-    assignType(enumerationMemberLiteral, AST::TypeReference::wrap(Lexer::Token(enumerationMemberLiteral.origin()), enumerationDefinition));
+    assignType(enumerationMemberLiteral, AST::TypeReference::wrap(enumerationMemberLiteral.codeLocation(), enumerationDefinition));
 }
 
 bool Checker::isBoolType(ResolvingType& resolvingType)
@@ -1224,7 +1224,7 @@ void Checker::visit(AST::LogicalNotExpression& logicalNotExpression)
 {
     if (!recurseAndRequireBoolType(logicalNotExpression.operand()))
         return;
-    assignType(logicalNotExpression, AST::TypeReference::wrap(Lexer::Token(logicalNotExpression.origin()), m_intrinsics.boolType()));
+    assignType(logicalNotExpression, AST::TypeReference::wrap(logicalNotExpression.codeLocation(), m_intrinsics.boolType()));
 }
 
 void Checker::visit(AST::LogicalExpression& logicalExpression)
@@ -1233,7 +1233,7 @@ void Checker::visit(AST::LogicalExpression& logicalExpression)
         return;
     if (!recurseAndRequireBoolType(logicalExpression.right()))
         return;
-    assignType(logicalExpression, AST::TypeReference::wrap(Lexer::Token(logicalExpression.origin()), m_intrinsics.boolType()));
+    assignType(logicalExpression, AST::TypeReference::wrap(logicalExpression.codeLocation(), m_intrinsics.boolType()));
 }
 
 void Checker::visit(AST::IfStatement& ifStatement)
@@ -1486,7 +1486,7 @@ void Checker::visit(AST::CallExpression& callExpression)
         return;
     }
 
-    auto* function = resolveFunction(m_program, functions, types, callExpression.name(), callExpression.origin(), m_intrinsics, callExpression.castReturnType());
+    auto* function = resolveFunction(m_program, functions, types, callExpression.name(), callExpression.codeLocation(), m_intrinsics, callExpression.castReturnType());
     if (!function) {
         setError();
         return;
index 6e75cc9..39e06d9 100644 (file)
@@ -88,7 +88,7 @@ static Optional<UniqueRef<AST::UnnamedType>> matchAndCommit(AST::Type& unifyNode
         return WTF::nullopt;
     if (is<AST::NamedType>(unifyNode)) {
         auto& namedUnifyNode = downcast<AST::NamedType>(unifyNode);
-        auto result = AST::TypeReference::wrap(Lexer::Token(namedUnifyNode.origin()), namedUnifyNode);
+        auto result = AST::TypeReference::wrap(namedUnifyNode.codeLocation(), namedUnifyNode);
         resolvableType.resolve(result->clone());
         return { WTFMove(result) };
     }
index ced1362..b59d16d 100644 (file)
@@ -32,7 +32,7 @@ namespace WebCore {
 
 namespace WHLSL {
 
-const char* Lexer::Token::typeName(Type type)
+const char* Token::typeName(Type type)
 {
     switch (type) {
     case Type::IntLiteral:
@@ -382,7 +382,7 @@ auto Lexer::consumeTokenFromStream() -> Token
         auto oldOffset = m_offset;
         m_offset = newOffset;
         skipWhitespaceAndComments();
-        return { oldOffset, newOffset, type };
+        return { { oldOffset, newOffset }, type };
     };
 
     if (auto newOffset = identifier(m_offset)) {
index e2e22aa..2e3f14f 100644 (file)
@@ -38,6 +38,163 @@ namespace WebCore {
 
 namespace WHLSL {
 
+struct Token;
+
+namespace AST {
+
+class CodeLocation {
+public:
+    CodeLocation() = default;
+    CodeLocation(unsigned startOffset, unsigned endOffset)
+        : m_startOffset(startOffset)
+        , m_endOffset(endOffset)
+    { }
+    inline CodeLocation(const Token&);
+    CodeLocation(const CodeLocation& location1, const CodeLocation& location2)
+        : m_startOffset(location1.startOffset())
+        , m_endOffset(location2.endOffset())
+    { }
+
+    unsigned startOffset() const { return m_startOffset; }
+    unsigned endOffset() const { return m_endOffset; }
+
+private:
+    unsigned m_startOffset { 0 };
+    unsigned m_endOffset { 0 };
+};
+
+} // namespace AST
+
+class Lexer;
+
+struct Token {
+    AST::CodeLocation codeLocation;
+    enum class Type : uint8_t {
+        IntLiteral,
+        UintLiteral,
+        FloatLiteral,
+        Struct,
+        Typedef,
+        Enum,
+        Operator,
+        If,
+        Else,
+        Continue,
+        Break,
+        Switch,
+        Case,
+        Default,
+        Fallthrough,
+        For,
+        While,
+        Do,
+        Return,
+        Trap,
+        Null,
+        True,
+        False,
+        Constant,
+        Device,
+        Threadgroup,
+        Thread,
+        Space,
+        Vertex,
+        Fragment,
+        Compute,
+        NumThreads,
+        SVInstanceID,
+        SVVertexID,
+        PSize,
+        SVPosition,
+        SVIsFrontFace,
+        SVSampleIndex,
+        SVInnerCoverage,
+        SVTarget,
+        SVDepth,
+        SVCoverage,
+        SVDispatchThreadID,
+        SVGroupID,
+        SVGroupIndex,
+        SVGroupThreadID,
+        Attribute,
+        Register,
+        Specialized,
+        Native,
+        Restricted,
+        Underscore,
+        Auto,
+        Protocol,
+        Const,
+        Static,
+        Qualifier,
+        Identifier,
+        OperatorName,
+        EqualsSign,
+        Semicolon,
+        LeftCurlyBracket,
+        RightCurlyBracket,
+        Colon,
+        Comma,
+        LeftParenthesis,
+        RightParenthesis,
+        SquareBracketPair,
+        LeftSquareBracket,
+        RightSquareBracket,
+        Star,
+        LessThanSign,
+        GreaterThanSign,
+        FullStop,
+        PlusEquals,
+        MinusEquals,
+        TimesEquals,
+        DivideEquals,
+        ModEquals,
+        XorEquals,
+        AndEquals,
+        OrEquals,
+        RightShiftEquals,
+        LeftShiftEquals,
+        PlusPlus,
+        MinusMinus,
+        Arrow,
+        QuestionMark,
+        OrOr,
+        AndAnd,
+        Or,
+        Xor,
+        And,
+        LessThanOrEqualTo,
+        GreaterThanOrEqualTo,
+        EqualComparison,
+        NotEqual,
+        RightShift,
+        LeftShift,
+        Plus,
+        Minus,
+        Divide,
+        Mod,
+        Tilde,
+        ExclamationPoint,
+        At,
+        EndOfFile,
+        Invalid
+    } type {Type::Invalid};
+
+    static const char* typeName(Type);
+
+    inline StringView stringView(const Lexer&) const;
+
+    unsigned startOffset() const
+    {
+        return codeLocation.startOffset();
+    }
+};
+
+AST::CodeLocation::CodeLocation(const Token& token)
+    : m_startOffset(token.codeLocation.startOffset())
+    , m_endOffset(token.codeLocation.endOffset())
+{ }
+
 class Lexer {
 public:
     Lexer() = default;
@@ -56,127 +213,6 @@ public:
     Lexer& operator=(const Lexer&) = delete;
     Lexer& operator=(Lexer&&) = default;
 
-    struct Token {
-        unsigned startOffset;
-        unsigned endOffset;
-        enum class Type : uint8_t {
-            IntLiteral,
-            UintLiteral,
-            FloatLiteral,
-            Struct,
-            Typedef,
-            Enum,
-            Operator,
-            If,
-            Else,
-            Continue,
-            Break,
-            Switch,
-            Case,
-            Default,
-            Fallthrough,
-            For,
-            While,
-            Do,
-            Return,
-            Trap,
-            Null,
-            True,
-            False,
-            Constant,
-            Device,
-            Threadgroup,
-            Thread,
-            Space,
-            Vertex,
-            Fragment,
-            Compute,
-            NumThreads,
-            SVInstanceID,
-            SVVertexID,
-            PSize,
-            SVPosition,
-            SVIsFrontFace,
-            SVSampleIndex,
-            SVInnerCoverage,
-            SVTarget,
-            SVDepth,
-            SVCoverage,
-            SVDispatchThreadID,
-            SVGroupID,
-            SVGroupIndex,
-            SVGroupThreadID,
-            Attribute,
-            Register,
-            Specialized,
-            Native,
-            Restricted,
-            Underscore,
-            Auto,
-            Protocol,
-            Const,
-            Static,
-            Qualifier,
-            Identifier,
-            OperatorName,
-            EqualsSign,
-            Semicolon,
-            LeftCurlyBracket,
-            RightCurlyBracket,
-            Colon,
-            Comma,
-            LeftParenthesis,
-            RightParenthesis,
-            SquareBracketPair,
-            LeftSquareBracket,
-            RightSquareBracket,
-            Star,
-            LessThanSign,
-            GreaterThanSign,
-            FullStop,
-            PlusEquals,
-            MinusEquals,
-            TimesEquals,
-            DivideEquals,
-            ModEquals,
-            XorEquals,
-            AndEquals,
-            OrEquals,
-            RightShiftEquals,
-            LeftShiftEquals,
-            PlusPlus,
-            MinusMinus,
-            Arrow,
-            QuestionMark,
-            OrOr,
-            AndAnd,
-            Or,
-            Xor,
-            And,
-            LessThanOrEqualTo,
-            GreaterThanOrEqualTo,
-            EqualComparison,
-            NotEqual,
-            RightShift,
-            LeftShift,
-            Plus,
-            Minus,
-            Divide,
-            Mod,
-            Tilde,
-            ExclamationPoint,
-            At,
-            EndOfFile,
-            Invalid
-        } type {Type::Invalid};
-
-        static const char* typeName(Type);
-
-        const StringView stringView(const Lexer& lexer)
-        {
-            return lexer.m_stringView.substring(startOffset, endOffset - startOffset);
-        }
-    };
 
     Token consumeToken()
     {
@@ -238,10 +274,11 @@ public:
 
     String errorString(const Token& token, const String& message)
     {
-        return makeString("Parse error at line ", lineNumberFromOffset(token.startOffset), ": ", message);
+        return makeString("Parse error at line ", lineNumberFromOffset(token.startOffset()), ": ", message);
     }
 
 private:
+    friend struct Token;
     Token consumeTokenFromStream();
 
     void skipWhitespaceAndComments();
@@ -286,6 +323,11 @@ template<unsigned length> Optional<unsigned> Lexer::string(const char (&string)[
     return offset + length - 1;
 }
 
+StringView Token::stringView(const Lexer& lexer) const
+{
+    return lexer.m_stringView.substring(codeLocation.startOffset(), codeLocation.endOffset() - codeLocation.startOffset());
+}
+
 } // namespace WHLSL
 
 } // namespace WebCore
index 2c3a2d7..6b83c64 100644 (file)
@@ -213,8 +213,7 @@ void NameResolver::visit(AST::DotExpression& dotExpression)
                 AST::EnumerationDefinition& enumerationDefinition = downcast<AST::EnumerationDefinition>(type);
                 auto memberName = dotExpression.fieldName();
                 if (auto* member = enumerationDefinition.memberByName(memberName)) {
-                    Lexer::Token origin = dotExpression.origin();
-                    auto enumerationMemberLiteral = AST::EnumerationMemberLiteral::wrap(WTFMove(origin), WTFMove(baseName), WTFMove(memberName), enumerationDefinition, *member);
+                    auto enumerationMemberLiteral = AST::EnumerationMemberLiteral::wrap(dotExpression.codeLocation(), WTFMove(baseName), WTFMove(memberName), enumerationDefinition, *member);
                     AST::replaceWith<AST::EnumerationMemberLiteral>(dotExpression, WTFMove(enumerationMemberLiteral));
                     return;
                 }
index 22b1a9b..8f1b945 100644 (file)
@@ -41,10 +41,10 @@ namespace WHLSL {
 #define PARSE(name, element, ...) \
     auto name = parse##element(__VA_ARGS__); \
     if (!name) \
-        return Unexpected<Error>(name.error());
+        return Unexpected<Error>(name.error()); \
 
 #define CONSUME_TYPE(name, type) \
-    auto name = consumeType(Lexer::Token::Type::type); \
+    auto name = consumeType(Token::Type::type); \
     if (!name) \
         return Unexpected<Error>(name.error());
 
@@ -67,38 +67,38 @@ auto Parser::parse(Program& program, StringView stringView, Mode mode) -> Option
     while (!m_lexer.isFullyConsumed()) {
         auto token = m_lexer.peek();
         switch (token.type) {
-        case Lexer::Token::Type::Invalid:
+        case Token::Type::Invalid:
             return WTF::nullopt;
-        case Lexer::Token::Type::Semicolon:
+        case Token::Type::Semicolon:
             m_lexer.consumeToken();
             continue;
-        case Lexer::Token::Type::Typedef: {
+        case Token::Type::Typedef: {
             auto typeDefinition = parseTypeDefinition();
             if (!typeDefinition)
                 return typeDefinition.error();
             program.append(WTFMove(*typeDefinition));
             continue;
         }
-        case Lexer::Token::Type::Struct: {
+        case Token::Type::Struct: {
             auto structureDefinition = parseStructureDefinition();
             if (!structureDefinition)
                 return structureDefinition.error();
             program.append(WTFMove(*structureDefinition));
             continue;
         }
-        case Lexer::Token::Type::Enum: {
+        case Token::Type::Enum: {
             auto enumerationDefinition = parseEnumerationDefinition();
             if (!enumerationDefinition)
                 return enumerationDefinition.error();
             program.append(WTFMove(*enumerationDefinition));
             continue;
         }
-        case Lexer::Token::Type::Native: {
+        case Token::Type::Native: {
             ASSERT(m_mode == Mode::StandardLibrary);
             auto furtherToken = peekFurther();
             if (!furtherToken)
                 return WTF::nullopt;
-            if (furtherToken->type == Lexer::Token::Type::Typedef) {
+            if (furtherToken->type == Token::Type::Typedef) {
                 auto nativeTypeDeclaration = parseNativeTypeDeclaration();
                 if (!nativeTypeDeclaration)
                     return nativeTypeDeclaration.error();
@@ -133,57 +133,64 @@ auto Parser::fail(const String& message, TryToPeek tryToPeek) -> Unexpected<Erro
     return Unexpected<Error>(Error(makeString("Cannot lex: ", message)));
 }
 
-auto Parser::peek() -> Expected<Lexer::Token, Error>
+auto Parser::peek() -> Expected<Token, Error>
 {
     auto token = m_lexer.peek();
-    if (token.type != Lexer::Token::Type::Invalid && token.type != Lexer::Token::Type::EndOfFile)
+    if (token.type != Token::Type::Invalid && token.type != Token::Type::EndOfFile)
         return { token };
     return fail("Cannot consume token"_str, TryToPeek::No);
 }
 
-auto Parser::peekFurther() -> Expected<Lexer::Token, Error>
+auto Parser::peekFurther() -> Expected<Token, Error>
 {
     auto token = m_lexer.peekFurther();
-    if (token.type != Lexer::Token::Type::Invalid && token.type != Lexer::Token::Type::EndOfFile)
+    if (token.type != Token::Type::Invalid && token.type != Token::Type::EndOfFile)
         return { token };
     return fail("Cannot consume two tokens"_str, TryToPeek::No);
 }
 
-template <Lexer::Token::Type t, Lexer::Token::Type... ts>
+template <Token::Type t, Token::Type... ts>
 struct Types {
-    static bool includes(Lexer::Token::Type type)
+    static bool includes(Token::Type type)
     {
         return t == type || Types<ts...>::includes(type);
     }
 
     static void appendNameTo(StringBuilder& builder)
     {
-        builder.append(Lexer::Token::typeName(t));
+        builder.append(Token::typeName(t));
         builder.append(", ");
         Types<ts...>::appendNameTo(builder);
     }
 };
-template <Lexer::Token::Type t>
+template <Token::Type t>
 struct Types<t> {
-    static bool includes(Lexer::Token::Type type)
+    static bool includes(Token::Type type)
     {
         return t == type;
     }
 
     static void appendNameTo(StringBuilder& builder)
     {
-        builder.append(Lexer::Token::typeName(t));
+        builder.append(Token::typeName(t));
     }
 };
 
-template <Lexer::Token::Type... types>
+
+bool Parser::peekType(Token::Type type)
+{
+    auto token = m_lexer.peek();
+    return token.type == type;
+}
+
+template <Token::Type... types>
 bool Parser::peekTypes()
 {
     auto token = m_lexer.peek();
     return Types<types...>::includes(token.type);
 }
 
-Optional<Lexer::Token> Parser::tryType(Lexer::Token::Type type)
+Optional<Token> Parser::tryType(Token::Type type)
 {
     auto token = m_lexer.peek();
     if (token.type == type)
@@ -191,8 +198,8 @@ Optional<Lexer::Token> Parser::tryType(Lexer::Token::Type type)
     return WTF::nullopt;
 }
 
-template <Lexer::Token::Type... types>
-Optional<Lexer::Token> Parser::tryTypes()
+template <Token::Type... types>
+Optional<Token> Parser::tryTypes()
 {
     auto token = m_lexer.peek();
     if (Types<types...>::includes(token.type))
@@ -200,16 +207,16 @@ Optional<Lexer::Token> Parser::tryTypes()
     return WTF::nullopt;
 }
 
-auto Parser::consumeType(Lexer::Token::Type type) -> Expected<Lexer::Token, Error>
+auto Parser::consumeType(Token::Type type) -> Expected<Token, Error>
 {
     auto token = m_lexer.consumeToken();
     if (token.type == type)
         return { token };
-    return fail(makeString("Unexpected token (expected ", Lexer::Token::typeName(type), " got ", Lexer::Token::typeName(token.type), ")"));
+    return fail(makeString("Unexpected token (expected ", Token::typeName(type), " got ", Token::typeName(token.type), ")"));
 }
 
-template <Lexer::Token::Type... types>
-auto Parser::consumeTypes() -> Expected<Lexer::Token, Error>
+template <Token::Type... types>
+auto Parser::consumeTypes() -> Expected<Token, Error>
 {
     auto buildExpectedString = [&]() -> String {
         StringBuilder builder;
@@ -222,7 +229,7 @@ auto Parser::consumeTypes() -> Expected<Lexer::Token, Error>
     auto token = m_lexer.consumeToken();
     if (Types<types...>::includes(token.type))
         return { token };
-    return fail(makeString("Unexpected token (expected one of ", buildExpectedString(), " got ", Lexer::Token::typeName(token.type), ")"));
+    return fail(makeString("Unexpected token (expected one of ", buildExpectedString(), " got ", Token::typeName(token.type), ")"));
 }
 
 static int digitValue(UChar character)
@@ -298,19 +305,19 @@ static Expected<float, Parser::Error> floatLiteralToFloat(StringView text)
 
 auto Parser::consumeIntegralLiteral() -> Expected<Variant<int, unsigned>, Error>
 {
-    auto integralLiteralToken = consumeTypes<Lexer::Token::Type::IntLiteral, Lexer::Token::Type::UintLiteral>();
+    auto integralLiteralToken = consumeTypes<Token::Type::IntLiteral, Token::Type::UintLiteral>();
     if (!integralLiteralToken)
         return Unexpected<Error>(integralLiteralToken.error());
 
     switch (integralLiteralToken->type) {
-    case Lexer::Token::Type::IntLiteral: {
+    case Token::Type::IntLiteral: {
         auto result = intLiteralToInt(integralLiteralToken->stringView(m_lexer));
         if (result)
             return {{ *result }};
         return Unexpected<Error>(result.error());
     }
     default: {
-        ASSERT(integralLiteralToken->type == Lexer::Token::Type::UintLiteral);
+        ASSERT(integralLiteralToken->type == Token::Type::UintLiteral);
         auto result = uintLiteralToUint(integralLiteralToken->stringView(m_lexer));
         if (result)
             return {{ *result }};
@@ -355,46 +362,46 @@ static Expected<unsigned, Parser::Error> recognizeSimpleUnsignedInteger(StringVi
 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>();
+        Token::Type::IntLiteral,
+        Token::Type::UintLiteral,
+        Token::Type::FloatLiteral,
+        Token::Type::Null,
+        Token::Type::True,
+        Token::Type::False,
+        Token::Type::Identifier>();
     if (!type)
         return Unexpected<Error>(type.error());
 
     switch (type->type) {
-    case Lexer::Token::Type::IntLiteral: {
+    case Token::Type::IntLiteral: {
         auto value = intLiteralToInt(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return {{ AST::IntegerLiteral(WTFMove(*type), *value) }};
+        return {{ AST::IntegerLiteral({ *type }, *value) }};
     }
-    case Lexer::Token::Type::UintLiteral: {
+    case Token::Type::UintLiteral: {
         auto value = uintLiteralToUint(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return {{ AST::UnsignedIntegerLiteral(WTFMove(*type), *value) }};
+        return {{ AST::UnsignedIntegerLiteral({ *type }, *value) }};
     }
-    case Lexer::Token::Type::FloatLiteral: {
+    case Token::Type::FloatLiteral: {
         auto value = floatLiteralToFloat(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return {{ AST::FloatLiteral(WTFMove(*type), *value) }};
+        return {{ AST::FloatLiteral({ *type }, *value) }};
     }
-    case Lexer::Token::Type::Null:
+    case Token::Type::Null:
         return { AST::NullLiteral(WTFMove(*type)) };
-    case Lexer::Token::Type::True:
+    case Token::Type::True:
         return { AST::BooleanLiteral(WTFMove(*type), true) };
-    case Lexer::Token::Type::False:
+    case Token::Type::False:
         return { AST::BooleanLiteral(WTFMove(*type), false) };
     default: {
-        ASSERT(type->type == Lexer::Token::Type::Identifier);
-        CONSUME_TYPE(origin, FullStop);
+        ASSERT(type->type == Token::Type::Identifier);
+        CONSUME_TYPE(fullStop, FullStop);
         CONSUME_TYPE(next, Identifier);
-        return { AST::EnumerationMemberLiteral(WTFMove(*origin), type->stringView(m_lexer).toString(), next->stringView(m_lexer).toString()) };
+        return { AST::EnumerationMemberLiteral({ *type, *next }, type->stringView(m_lexer).toString(), next->stringView(m_lexer).toString()) };
     }
     }
 }
@@ -403,22 +410,23 @@ auto Parser::parseTypeArgument() -> Expected<AST::TypeArgument, Error>
 {
     PEEK(nextToken);
     PEEK_FURTHER(furtherToken);
-    if (nextToken->type != Lexer::Token::Type::Identifier || furtherToken->type == Lexer::Token::Type::FullStop) {
+    if (nextToken->type != Token::Type::Identifier || furtherToken->type == Token::Type::FullStop) {
         PARSE(constantExpression, ConstantExpression);
         return AST::TypeArgument(WTFMove(*constantExpression));
     }
     CONSUME_TYPE(result, Identifier);
-    return AST::TypeArgument(makeUniqueRef<AST::TypeReference>(Lexer::Token(*result), result->stringView(m_lexer).toString(), AST::TypeArguments()));
+    AST::CodeLocation location(*result);
+    return AST::TypeArgument(makeUniqueRef<AST::TypeReference>(location, result->stringView(m_lexer).toString(), AST::TypeArguments()));
 }
 
 auto Parser::parseTypeArguments() -> Expected<AST::TypeArguments, Error>
 {
     AST::TypeArguments typeArguments;
-    auto lessThanSign = tryType(Lexer::Token::Type::LessThanSign);
+    auto lessThanSign = tryType(Token::Type::LessThanSign);
     if (!lessThanSign)
         return typeArguments;
 
-    auto greaterThanSign = tryType(Lexer::Token::Type::GreaterThanSign);
+    auto greaterThanSign = tryType(Token::Type::GreaterThanSign);
     if (greaterThanSign)
         return typeArguments;
 
@@ -426,7 +434,7 @@ auto Parser::parseTypeArguments() -> Expected<AST::TypeArguments, Error>
     typeArguments.append(WTFMove(*typeArgument));
 
     while (true) {
-        auto greaterThanSign = tryType(Lexer::Token::Type::GreaterThanSign);
+        auto greaterThanSign = tryType(Token::Type::GreaterThanSign);
         if (greaterThanSign)
             break;
 
@@ -441,69 +449,69 @@ auto Parser::parseTypeArguments() -> Expected<AST::TypeArguments, Error>
 auto Parser::parseTypeSuffixAbbreviated() -> Expected<TypeSuffixAbbreviated, Error>
 {
     auto token = consumeTypes<
-        Lexer::Token::Type::Star,
-        Lexer::Token::Type::SquareBracketPair,
-        Lexer::Token::Type::LeftSquareBracket>();
+        Token::Type::Star,
+        Token::Type::SquareBracketPair,
+        Token::Type::LeftSquareBracket>();
     if (!token)
         return Unexpected<Error>(token.error());
-    if (token->type == Lexer::Token::Type::LeftSquareBracket) {
+    if (token->type == Token::Type::LeftSquareBracket) {
         auto numElements = consumeNonNegativeIntegralLiteral();
         if (!numElements)
             return Unexpected<Error>(numElements.error());
         CONSUME_TYPE(rightSquareBracket, RightSquareBracket);
-        return {{ *token, *numElements }};
+        return {{ { *token, *rightSquareBracket }, *token, *numElements }};
     }
-    return {{ *token, WTF::nullopt }};
+    return {{ { *token }, *token, WTF::nullopt }};
 }
 
 auto Parser::parseTypeSuffixNonAbbreviated() -> Expected<TypeSuffixNonAbbreviated, Error>
 {
     auto token = consumeTypes<
-        Lexer::Token::Type::Star,
-        Lexer::Token::Type::SquareBracketPair,
-        Lexer::Token::Type::LeftSquareBracket>();
+        Token::Type::Star,
+        Token::Type::SquareBracketPair,
+        Token::Type::LeftSquareBracket>();
     if (!token)
         return Unexpected<Error>(token.error());
-    if (token->type == Lexer::Token::Type::LeftSquareBracket) {
+    if (token->type == Token::Type::LeftSquareBracket) {
         auto numElements = consumeNonNegativeIntegralLiteral();
         if (!numElements)
             return Unexpected<Error>(numElements.error());
         CONSUME_TYPE(rightSquareBracket, RightSquareBracket);
-        return {{ *token, WTF::nullopt, *numElements }};
+        return {{ { *token, *rightSquareBracket }, *token, WTF::nullopt, *numElements }};
     }
     auto addressSpaceToken = consumeTypes<
-        Lexer::Token::Type::Constant,
-        Lexer::Token::Type::Device,
-        Lexer::Token::Type::Threadgroup,
-        Lexer::Token::Type::Thread>();
+        Token::Type::Constant,
+        Token::Type::Device,
+        Token::Type::Threadgroup,
+        Token::Type::Thread>();
     if (!addressSpaceToken)
         return Unexpected<Error>(addressSpaceToken.error());
     AST::AddressSpace addressSpace;
     switch (addressSpaceToken->type) {
-    case Lexer::Token::Type::Constant:
+    case Token::Type::Constant:
         addressSpace = AST::AddressSpace::Constant;
         break;
-    case Lexer::Token::Type::Device:
+    case Token::Type::Device:
         addressSpace = AST::AddressSpace::Device;
         break;
-    case Lexer::Token::Type::Threadgroup:
+    case Token::Type::Threadgroup:
         addressSpace = AST::AddressSpace::Threadgroup;
         break;
     default:
-        ASSERT(addressSpaceToken->type == Lexer::Token::Type::Thread);
+        ASSERT(addressSpaceToken->type == Token::Type::Thread);
         addressSpace = AST::AddressSpace::Thread;
         break;
     }
-    return {{ *token, { addressSpace }, WTF::nullopt }};
+    return {{ { *token }, *token, { addressSpace }, WTF::nullopt }};
 }
 
 auto Parser::parseType() -> Expected<UniqueRef<AST::UnnamedType>, Error>
 {
     auto addressSpaceToken = tryTypes<
-        Lexer::Token::Type::Constant,
-        Lexer::Token::Type::Device,
-        Lexer::Token::Type::Threadgroup,
-        Lexer::Token::Type::Thread>();
+        Token::Type::Constant,
+        Token::Type::Device,
+        Token::Type::Threadgroup,
+        Token::Type::Thread>();
 
     CONSUME_TYPE(name, Identifier);
     PARSE(typeArguments, TypeArguments);
@@ -511,29 +519,30 @@ auto Parser::parseType() -> Expected<UniqueRef<AST::UnnamedType>, Error>
     if (addressSpaceToken) {
         AST::AddressSpace addressSpace;
         switch (addressSpaceToken->type) {
-        case Lexer::Token::Type::Constant:
+        case Token::Type::Constant:
             addressSpace = AST::AddressSpace::Constant;
             break;
-        case Lexer::Token::Type::Device:
+        case Token::Type::Device:
             addressSpace = AST::AddressSpace::Device;
             break;
-        case Lexer::Token::Type::Threadgroup:
+        case Token::Type::Threadgroup:
             addressSpace = AST::AddressSpace::Threadgroup;
             break;
         default:
-            ASSERT(addressSpaceToken->type == Lexer::Token::Type::Thread);
+            ASSERT(addressSpaceToken->type == Token::Type::Thread);
             addressSpace = AST::AddressSpace::Thread;
             break;
         }
         auto constructTypeFromSuffixAbbreviated = [&](const TypeSuffixAbbreviated& typeSuffixAbbreviated, UniqueRef<AST::UnnamedType>&& previous) -> UniqueRef<AST::UnnamedType> {
+            AST::CodeLocation location(*addressSpaceToken, typeSuffixAbbreviated.location);
             switch (typeSuffixAbbreviated.token.type) {
-            case Lexer::Token::Type::Star:
-                return { makeUniqueRef<AST::PointerType>(Lexer::Token(typeSuffixAbbreviated.token), addressSpace, WTFMove(previous)) };
-            case Lexer::Token::Type::SquareBracketPair:
-                return { makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(typeSuffixAbbreviated.token), addressSpace, WTFMove(previous)) };
+            case Token::Type::Star:
+                return { makeUniqueRef<AST::PointerType>(location, addressSpace, WTFMove(previous)) };
+            case Token::Type::SquareBracketPair:
+                return { makeUniqueRef<AST::ArrayReferenceType>(location, addressSpace, WTFMove(previous)) };
             default:
-                ASSERT(typeSuffixAbbreviated.token.type == Lexer::Token::Type::LeftSquareBracket);
-                return { makeUniqueRef<AST::ArrayType>(Lexer::Token(typeSuffixAbbreviated.token), WTFMove(previous), *typeSuffixAbbreviated.numElements) };
+                ASSERT(typeSuffixAbbreviated.token.type == Token::Type::LeftSquareBracket);
+                return { makeUniqueRef<AST::ArrayType>(location, WTFMove(previous), *typeSuffixAbbreviated.numElements) };
             }
         };
         PARSE(firstTypeSuffixAbbreviated, TypeSuffixAbbreviated);
@@ -542,9 +551,9 @@ auto Parser::parseType() -> Expected<UniqueRef<AST::UnnamedType>, Error>
         result = WTFMove(next);
         while (true) {
             PEEK(nextToken);
-            if (nextToken->type != Lexer::Token::Type::Star
-                && nextToken->type != Lexer::Token::Type::SquareBracketPair
-                && nextToken->type != Lexer::Token::Type::LeftSquareBracket) {
+            if (nextToken->type != Token::Type::Star
+                && nextToken->type != Token::Type::SquareBracketPair
+                && nextToken->type != Token::Type::LeftSquareBracket) {
                 break;
             }
             PARSE(typeSuffixAbbreviated, TypeSuffixAbbreviated);
@@ -556,22 +565,23 @@ auto Parser::parseType() -> Expected<UniqueRef<AST::UnnamedType>, Error>
     }
 
     auto constructTypeFromSuffixNonAbbreviated = [&](const TypeSuffixNonAbbreviated& typeSuffixNonAbbreviated, UniqueRef<AST::UnnamedType>&& previous) -> UniqueRef<AST::UnnamedType> {
+        AST::CodeLocation location(*name, typeSuffixNonAbbreviated.location);
         switch (typeSuffixNonAbbreviated.token.type) {
-        case Lexer::Token::Type::Star:
-            return { makeUniqueRef<AST::PointerType>(Lexer::Token(typeSuffixNonAbbreviated.token), *typeSuffixNonAbbreviated.addressSpace, WTFMove(previous)) };
-        case Lexer::Token::Type::SquareBracketPair:
-            return { makeUniqueRef<AST::ArrayReferenceType>(Lexer::Token(typeSuffixNonAbbreviated.token), *typeSuffixNonAbbreviated.addressSpace, WTFMove(previous)) };
+        case Token::Type::Star:
+            return { makeUniqueRef<AST::PointerType>(location, *typeSuffixNonAbbreviated.addressSpace, WTFMove(previous)) };
+        case Token::Type::SquareBracketPair:
+            return { makeUniqueRef<AST::ArrayReferenceType>(location, *typeSuffixNonAbbreviated.addressSpace, WTFMove(previous)) };
         default:
-            ASSERT(typeSuffixNonAbbreviated.token.type == Lexer::Token::Type::LeftSquareBracket);
-            return { makeUniqueRef<AST::ArrayType>(Lexer::Token(typeSuffixNonAbbreviated.token), WTFMove(previous), *typeSuffixNonAbbreviated.numElements) };
+            ASSERT(typeSuffixNonAbbreviated.token.type == Token::Type::LeftSquareBracket);
+            return { makeUniqueRef<AST::ArrayType>(location, WTFMove(previous), *typeSuffixNonAbbreviated.numElements) };
         }
     };
-    UniqueRef<AST::UnnamedType> result = makeUniqueRef<AST::TypeReference>(WTFMove(*name), name->stringView(m_lexer).toString(), WTFMove(*typeArguments));
+    UniqueRef<AST::UnnamedType> result = makeUniqueRef<AST::TypeReference>(*name, name->stringView(m_lexer).toString(), WTFMove(*typeArguments));
     while (true) {
         PEEK(nextToken);
-        if (nextToken->type != Lexer::Token::Type::Star
-            && nextToken->type != Lexer::Token::Type::SquareBracketPair
-            && nextToken->type != Lexer::Token::Type::LeftSquareBracket) {
+        if (nextToken->type != Token::Type::Star
+            && nextToken->type != Token::Type::SquareBracketPair
+            && nextToken->type != Token::Type::LeftSquareBracket) {
             break;
         }
         PARSE(typeSuffixNonAbbreviated, TypeSuffixNonAbbreviated);
@@ -589,63 +599,63 @@ auto Parser::parseTypeDefinition() -> Expected<AST::TypeDefinition, Error>
     CONSUME_TYPE(equals, EqualsSign);
     PARSE(type, Type);
     CONSUME_TYPE(semicolon, Semicolon);
-    return AST::TypeDefinition(WTFMove(*origin), name->stringView(m_lexer).toString(), WTFMove(*type));
+    return AST::TypeDefinition({ *origin, *semicolon }, name->stringView(m_lexer).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>();
+        Token::Type::SVInstanceID,
+        Token::Type::SVVertexID,
+        Token::Type::PSize,
+        Token::Type::SVPosition,
+        Token::Type::SVIsFrontFace,
+        Token::Type::SVSampleIndex,
+        Token::Type::SVInnerCoverage,
+        Token::Type::SVTarget,
+        Token::Type::SVDepth,
+        Token::Type::SVCoverage,
+        Token::Type::SVDispatchThreadID,
+        Token::Type::SVGroupID,
+        Token::Type::SVGroupIndex,
+        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: {
+    case Token::Type::SVInstanceID:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVInstanceID);
+    case Token::Type::SVVertexID:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVVertexID);
+    case Token::Type::PSize:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::PSize);
+    case Token::Type::SVPosition:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVPosition);
+    case Token::Type::SVIsFrontFace:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVIsFrontFace);
+    case Token::Type::SVSampleIndex:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVSampleIndex);
+    case Token::Type::SVInnerCoverage:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVInnerCoverage);
+    case Token::Type::SVTarget: {
         auto target = consumeNonNegativeIntegralLiteral(); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=195807 Make this work with strings like "SV_Target0".
         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);
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVTarget, *target);
+    }
+    case Token::Type::SVDepth:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVDepth);
+    case Token::Type::SVCoverage:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVCoverage);
+    case Token::Type::SVDispatchThreadID:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVDispatchThreadID);
+    case Token::Type::SVGroupID:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVGroupID);
+    case Token::Type::SVGroupIndex:
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVGroupIndex);
     default:
-        ASSERT(origin->type == Lexer::Token::Type::SVGroupThreadID);
-        return AST::BuiltInSemantic(WTFMove(*origin), AST::BuiltInSemantic::Variable::SVGroupThreadID);
+        ASSERT(origin->type == Token::Type::SVGroupThreadID);
+        return AST::BuiltInSemantic({ *origin }, AST::BuiltInSemantic::Variable::SVGroupThreadID);
     }
 }
 
@@ -683,7 +693,7 @@ auto Parser::parseResourceSemantic() -> Expected<AST::ResourceSemantic, Error>
         return Unexpected<Error>(index.error());
 
     unsigned space = 0;
-    if (tryType(Lexer::Token::Type::Comma)) {
+    if (tryType(Token::Type::Comma)) {
         CONSUME_TYPE(spaceToken, Identifier);
         auto spaceTokenStringView = spaceToken->stringView(m_lexer);
         auto prefix = "space"_str;
@@ -699,13 +709,13 @@ auto Parser::parseResourceSemantic() -> Expected<AST::ResourceSemantic, Error>
 
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
 
-    return AST::ResourceSemantic(WTFMove(*origin), mode, *index, space);
+    return AST::ResourceSemantic({ *origin, *rightParenthesis }, mode, *index, space);
 }
 
 auto Parser::parseSpecializationConstantSemantic() -> Expected<AST::SpecializationConstantSemantic, Error>
 {
     CONSUME_TYPE(origin, Specialized);
-    return AST::SpecializationConstantSemantic(WTFMove(*origin));
+    return AST::SpecializationConstantSemantic(*origin);
 }
 
 auto Parser::parseStageInOutSemantic() -> Expected<AST::StageInOutSemantic, Error>
@@ -719,25 +729,25 @@ auto Parser::parseStageInOutSemantic() -> Expected<AST::StageInOutSemantic, Erro
 
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
 
-    return AST::StageInOutSemantic(WTFMove(*origin), *index);
+    return AST::StageInOutSemantic({ *origin, *rightParenthesis }, *index);
 }
 
 auto Parser::parseSemantic() -> Expected<std::unique_ptr<AST::Semantic>, Error>
 {
-    if (!tryType(Lexer::Token::Type::Colon))
+    if (!tryType(Token::Type::Colon))
         return { nullptr };
 
     PEEK(token);
     switch (token->type) {
-    case Lexer::Token::Type::Attribute: {
+    case Token::Type::Attribute: {
         PARSE(result, StageInOutSemantic);
         return { std::make_unique<AST::Semantic>(WTFMove(*result)) };
     }
-    case Lexer::Token::Type::Specialized:  {
+    case Token::Type::Specialized:  {
         PARSE(result, SpecializationConstantSemantic);
         return { std::make_unique<AST::Semantic>(WTFMove(*result)) };
     }
-    case Lexer::Token::Type::Register:  {
+    case Token::Type::Register:  {
         PARSE(result, ResourceSemantic);
         return { std::make_unique<AST::Semantic>(WTFMove(*result)) };
     }
@@ -750,7 +760,7 @@ auto Parser::parseSemantic() -> Expected<std::unique_ptr<AST::Semantic>, Error>
 AST::Qualifiers Parser::parseQualifiers()
 {
     AST::Qualifiers qualifiers;
-    while (auto next = tryType(Lexer::Token::Type::Qualifier)) {
+    while (auto next = tryType(Token::Type::Qualifier)) {
         auto nextStringView = next->stringView(m_lexer);
         if ("nointerpolation" == nextStringView)
             qualifiers.append(AST::Qualifier::Nointerpolation);
@@ -779,7 +789,7 @@ auto Parser::parseStructureElement() -> Expected<AST::StructureElement, Error>
     PARSE(semantic, Semantic);
     CONSUME_TYPE(semicolon, Semicolon);
 
-    return AST::StructureElement(WTFMove(*origin), WTFMove(qualifiers), WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*semantic));
+    return AST::StructureElement({ *origin, *semicolon }, WTFMove(qualifiers), WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*semantic));
 }
 
 auto Parser::parseStructureDefinition() -> Expected<AST::StructureDefinition, Error>
@@ -789,12 +799,14 @@ auto Parser::parseStructureDefinition() -> Expected<AST::StructureDefinition, Er
     CONSUME_TYPE(leftCurlyBracket, LeftCurlyBracket);
 
     AST::StructureElements structureElements;
-    while (!tryType(Lexer::Token::Type::RightCurlyBracket)) {
+    while (!peekType(Token::Type::RightCurlyBracket)) {
         PARSE(structureElement, StructureElement);
         structureElements.append(WTFMove(*structureElement));
     }
 
-    return AST::StructureDefinition(WTFMove(*origin), name->stringView(m_lexer).toString(), WTFMove(structureElements));
+    auto rightCurlyBracket = m_lexer.consumeToken();
+
+    return AST::StructureDefinition({ *origin, rightCurlyBracket }, name->stringView(m_lexer).toString(), WTFMove(structureElements));
 }
 
 auto Parser::parseEnumerationDefinition() -> Expected<AST::EnumerationDefinition, Error>
@@ -803,11 +815,11 @@ auto Parser::parseEnumerationDefinition() -> Expected<AST::EnumerationDefinition
     CONSUME_TYPE(name, Identifier);
 
     auto type = ([&]() -> Expected<UniqueRef<AST::UnnamedType>, Error> {
-        if (tryType(Lexer::Token::Type::Colon)) {
+        if (tryType(Token::Type::Colon)) {
             PARSE(parsedType, Type);
             return WTFMove(*parsedType);
         }
-        return { makeUniqueRef<AST::TypeReference>(Lexer::Token(*origin), "int"_str, AST::TypeArguments()) };
+        return { makeUniqueRef<AST::TypeReference>(*origin, "int"_str, AST::TypeArguments()) };
     })();
     if (!type)
         return Unexpected<Error>(type.error());
@@ -816,12 +828,12 @@ auto Parser::parseEnumerationDefinition() -> Expected<AST::EnumerationDefinition
 
     PARSE(firstEnumerationMember, EnumerationMember);
 
-    AST::EnumerationDefinition result(WTFMove(*origin), name->stringView(m_lexer).toString(), WTFMove(*type));
+    AST::EnumerationDefinition result({ }, name->stringView(m_lexer).toString(), WTFMove(*type));
     auto success = result.add(WTFMove(*firstEnumerationMember));
     if (!success)
         return fail("Cannot add enumeration member"_str);
 
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         PARSE(member, EnumerationMember);
         success = result.add(WTFMove(*member));
         if (!success)
@@ -829,6 +841,7 @@ auto Parser::parseEnumerationDefinition() -> Expected<AST::EnumerationDefinition
     }
 
     CONSUME_TYPE(rightCurlyBracket, RightCurlyBracket);
+    result.updateCodeLocation({ *origin, *rightCurlyBracket});
 
     return WTFMove(result);
 }
@@ -838,11 +851,11 @@ auto Parser::parseEnumerationMember() -> Expected<AST::EnumerationMember, Error>
     CONSUME_TYPE(identifier, Identifier);
     auto name = identifier->stringView(m_lexer).toString();
 
-    if (tryType(Lexer::Token::Type::EqualsSign)) {
+    if (tryType(Token::Type::EqualsSign)) {
         PARSE(constantExpression, ConstantExpression);
-        return AST::EnumerationMember(Lexer::Token(*identifier), WTFMove(name), WTFMove(*constantExpression));
+        return AST::EnumerationMember(*identifier, WTFMove(name), WTFMove(*constantExpression));
     }
-    return AST::EnumerationMember(Lexer::Token(*identifier), WTFMove(name));
+    return AST::EnumerationMember(*identifier, WTFMove(name));
 }
 
 auto Parser::parseNativeTypeDeclaration() -> Expected<AST::NativeTypeDeclaration, Error>
@@ -853,7 +866,7 @@ auto Parser::parseNativeTypeDeclaration() -> Expected<AST::NativeTypeDeclaration
     PARSE(typeArguments, TypeArguments);
     CONSUME_TYPE(semicolon, Semicolon);
 
-    return AST::NativeTypeDeclaration(WTFMove(*origin), name->stringView(m_lexer).toString(), WTFMove(*typeArguments));
+    return AST::NativeTypeDeclaration({ *origin, *semicolon }, name->stringView(m_lexer).toString(), WTFMove(*typeArguments));
 }
 
 auto Parser::parseNumThreadsFunctionAttribute() -> Expected<AST::NumThreadsFunctionAttribute, Error>
@@ -879,7 +892,7 @@ auto Parser::parseNumThreadsFunctionAttribute() -> Expected<AST::NumThreadsFunct
 
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
 
-    return AST::NumThreadsFunctionAttribute(WTFMove(*origin), *width, *height, *depth);
+    return AST::NumThreadsFunctionAttribute({ *origin, *rightParenthesis }, *width, *height, *depth);
 }
 
 auto Parser::parseAttributeBlock() -> Expected<AST::AttributeBlock, Error>
@@ -888,9 +901,7 @@ auto Parser::parseAttributeBlock() -> Expected<AST::AttributeBlock, Error>
 
     AST::AttributeBlock result;
 
-    while (true) {
-        if (tryType(Lexer::Token::Type::RightSquareBracket))
-            break;
+    while (!tryType(Token::Type::RightSquareBracket)) {
         PARSE(numThreadsFunctionAttribute, NumThreadsFunctionAttribute);
         result.append(WTFMove(*numThreadsFunctionAttribute));
     }
@@ -900,19 +911,20 @@ auto Parser::parseAttributeBlock() -> Expected<AST::AttributeBlock, Error>
 
 auto Parser::parseParameter() -> Expected<AST::VariableDeclaration, Error>
 {
-    PEEK(origin);
+    auto startOffset = m_lexer.peek().startOffset();
 
     AST::Qualifiers qualifiers = parseQualifiers();
-
     PARSE(type, Type);
 
     String name;
-    if (auto token = tryType(Lexer::Token::Type::Identifier))
+    if (auto token = tryType(Token::Type::Identifier))
         name = token->stringView(m_lexer).toString();
 
     PARSE(semantic, Semantic);
 
-    return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), { WTFMove(*type) }, WTFMove(name), WTFMove(*semantic), nullptr);
+    auto endOffset = m_lexer.peek().startOffset();
+
+    return AST::VariableDeclaration({ startOffset, endOffset }, WTFMove(qualifiers), { WTFMove(*type) }, WTFMove(name), WTFMove(*semantic), nullptr);
 }
 
 auto Parser::parseParameters() -> Expected<AST::VariableDeclarations, Error>
@@ -921,13 +933,13 @@ auto Parser::parseParameters() -> Expected<AST::VariableDeclarations, Error>
 
     CONSUME_TYPE(leftParenthesis, LeftParenthesis);
 
-    if (tryType(Lexer::Token::Type::RightParenthesis))
+    if (tryType(Token::Type::RightParenthesis))
         return WTFMove(parameters);
 
     PARSE(firstParameter, Parameter);
     parameters.append(makeUniqueRef<AST::VariableDeclaration>(WTFMove(*firstParameter)));
 
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         PARSE(parameter, Parameter);
         parameters.append(makeUniqueRef<AST::VariableDeclaration>(WTFMove(*parameter)));
     }
@@ -954,24 +966,29 @@ auto Parser::parseComputeFunctionDeclaration() -> Expected<AST::FunctionDeclarat
     CONSUME_TYPE(name, Identifier);
     PARSE(parameters, Parameters);
     PARSE(semantic, Semantic);
+
+    auto endOffset = m_lexer.peek().startOffset();
+
     bool isOperator = false;
-    return AST::FunctionDeclaration(WTFMove(*origin), WTFMove(*attributeBlock), AST::EntryPointType::Compute, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
+    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, WTFMove(*attributeBlock), AST::EntryPointType::Compute, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
 }
 
 auto Parser::parseVertexOrFragmentFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error>
 {
-    auto entryPoint = consumeTypes<Lexer::Token::Type::Vertex, Lexer::Token::Type::Fragment>();
+    auto entryPoint = consumeTypes<Token::Type::Vertex, Token::Type::Fragment>();
     if (!entryPoint)
         return Unexpected<Error>(entryPoint.error());
-    auto entryPointType = (entryPoint->type == Lexer::Token::Type::Vertex) ? AST::EntryPointType::Vertex : AST::EntryPointType::Fragment;
+    auto entryPointType = (entryPoint->type == Token::Type::Vertex) ? AST::EntryPointType::Vertex : AST::EntryPointType::Fragment;
 
     PARSE(type, Type);
     CONSUME_TYPE(name, Identifier);
     PARSE(parameters, Parameters);
     PARSE(semantic, Semantic);
 
+    auto endOffset = m_lexer.peek().startOffset();
+
     bool isOperator = false;
-    return AST::FunctionDeclaration(WTFMove(*entryPoint), { }, entryPointType, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
+    return AST::FunctionDeclaration({ entryPoint->startOffset(), endOffset }, { }, entryPointType, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
 }
 
 auto Parser::parseRegularFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error>
@@ -980,15 +997,17 @@ auto Parser::parseRegularFunctionDeclaration() -> Expected<AST::FunctionDeclarat
 
     PARSE(type, Type);
 
-    auto name = consumeTypes<Lexer::Token::Type::Identifier, Lexer::Token::Type::OperatorName>();
+    auto name = consumeTypes<Token::Type::Identifier, Token::Type::OperatorName>();
     if (!name)
         return Unexpected<Error>(name.error());
-    auto isOperator = name->type == Lexer::Token::Type::OperatorName;
+    auto isOperator = name->type == Token::Type::OperatorName;
 
     PARSE(parameters, Parameters);
     PARSE(semantic, Semantic);
 
-    return AST::FunctionDeclaration(WTFMove(*origin), { }, WTF::nullopt, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
+    auto endOffset = m_lexer.peek().startOffset();
+
+    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), name->stringView(m_lexer).toString(), WTFMove(*parameters), WTFMove(*semantic), isOperator);
 }
 
 auto Parser::parseOperatorFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error>
@@ -998,20 +1017,22 @@ auto Parser::parseOperatorFunctionDeclaration() -> Expected<AST::FunctionDeclara
     PARSE(parameters, Parameters);
     PARSE(semantic, Semantic);
 
+    auto endOffset = m_lexer.peek().startOffset();
+
     bool isOperator = true;
-    return AST::FunctionDeclaration(WTFMove(*origin), { }, WTF::nullopt, WTFMove(*type), "operator cast"_str, WTFMove(*parameters), WTFMove(*semantic), isOperator);
+    return AST::FunctionDeclaration({ origin->startOffset(), endOffset }, { }, WTF::nullopt, WTFMove(*type), "operator cast"_str, WTFMove(*parameters), WTFMove(*semantic), isOperator);
 }
 
 auto Parser::parseFunctionDeclaration() -> Expected<AST::FunctionDeclaration, Error>
 {
     PEEK(token);
     switch (token->type) {
-    case Lexer::Token::Type::Operator:
+    case Token::Type::Operator:
         return parseOperatorFunctionDeclaration();
-    case Lexer::Token::Type::Vertex:
-    case Lexer::Token::Type::Fragment:
+    case Token::Type::Vertex:
+    case Token::Type::Fragment:
         return parseVertexOrFragmentFunctionDeclaration();
-    case Lexer::Token::Type::LeftSquareBracket:
+    case Token::Type::LeftSquareBracket:
         return parseComputeFunctionDeclaration();
     default:
         return parseRegularFunctionDeclaration();
@@ -1030,19 +1051,25 @@ auto Parser::parseNativeFunctionDeclaration() -> Expected<AST::NativeFunctionDec
 auto Parser::parseBlock() -> Expected<AST::Block, Error>
 {
     CONSUME_TYPE(origin, LeftCurlyBracket);
-    PARSE(result, BlockBody, WTFMove(*origin));
+    PARSE(result, BlockBody);
     CONSUME_TYPE(rightCurlyBracket, RightCurlyBracket);
+    result->updateCodeLocation({ *origin, *rightCurlyBracket });
     return WTFMove(*result);
 }
 
-auto Parser::parseBlockBody(Lexer::Token&& origin) -> Expected<AST::Block, Error>
+auto Parser::parseBlockBody() -> Expected<AST::Block, Error>
 {
+    auto startOffset = m_lexer.peek().startOffset();
+
     AST::Statements statements;
-    while (!peekTypes<Lexer::Token::Type::RightCurlyBracket, Lexer::Token::Type::Case, Lexer::Token::Type::Default>()) {
+    while (!peekTypes<Token::Type::RightCurlyBracket, Token::Type::Case, Token::Type::Default>()) {
         PARSE(statement, Statement);
         statements.append(WTFMove(*statement));
     }
-    return AST::Block(WTFMove(origin), WTFMove(statements));
+
+    auto endOffset = m_lexer.peek().startOffset();
+
+    return AST::Block({ startOffset, endOffset}, WTFMove(statements));
 }
 
 auto Parser::parseIfStatement() -> Expected<AST::IfStatement, Error>
@@ -1054,15 +1081,17 @@ auto Parser::parseIfStatement() -> Expected<AST::IfStatement, Error>
     PARSE(body, Statement);
 
     Optional<UniqueRef<AST::Statement>> elseBody;
-    if (tryType(Lexer::Token::Type::Else)) {
+    if (tryType(Token::Type::Else)) {
         PARSE(parsedElseBody, Statement);
         elseBody = WTFMove(*parsedElseBody);
     }
 
+    auto endOffset = m_lexer.peek().startOffset();
+
     Vector<UniqueRef<AST::Expression>> castArguments;
     castArguments.append(WTFMove(*conditional));
-    auto boolCast = makeUniqueRef<AST::CallExpression>(Lexer::Token(*origin), "bool"_str, WTFMove(castArguments));
-    return AST::IfStatement(WTFMove(*origin), WTFMove(boolCast), WTFMove(*body), WTFMove(elseBody));
+    auto boolCast = makeUniqueRef<AST::CallExpression>(Token(*origin), "bool"_str, WTFMove(castArguments));
+    return AST::IfStatement({ origin->startOffset(), endOffset }, WTFMove(boolCast), WTFMove(*body), WTFMove(elseBody));
 }
 
 auto Parser::parseSwitchStatement() -> Expected<AST::SwitchStatement, Error>
@@ -1075,40 +1104,40 @@ auto Parser::parseSwitchStatement() -> Expected<AST::SwitchStatement, Error>
 
     Vector<AST::SwitchCase> switchCases;
     PEEK(nextToken);
-    while (nextToken->type != Lexer::Token::Type::RightCurlyBracket) {
+    while (nextToken->type != Token::Type::RightCurlyBracket) {
         PARSE(switchCase, SwitchCase);
         switchCases.append(WTFMove(*switchCase));
         PEEK(nextTokenInLoop);
         nextToken = nextTokenInLoop;
     }
 
-    m_lexer.consumeToken();
+    auto endToken = m_lexer.consumeToken();
 
-    return AST::SwitchStatement(WTFMove(*origin), WTFMove(*value), WTFMove(switchCases));
+    return AST::SwitchStatement({ *origin, endToken }, WTFMove(*value), WTFMove(switchCases));
 }
 
 auto Parser::parseSwitchCase() -> Expected<AST::SwitchCase, Error>
 {
-    auto origin = consumeTypes<Lexer::Token::Type::Case, Lexer::Token::Type::Default>();
+    auto origin = consumeTypes<Token::Type::Case, Token::Type::Default>();
     if (!origin)
         return Unexpected<Error>(origin.error());
 
     switch (origin->type) {
-    case Lexer::Token::Type::Case: {
+    case Token::Type::Case: {
         PARSE(value, ConstantExpression);
         CONSUME_TYPE(colon, Colon);
 
-        PARSE(block, BlockBody, Lexer::Token(*origin));
+        PARSE(block, BlockBody);
 
-        return AST::SwitchCase(WTFMove(*origin), WTFMove(*value), WTFMove(*block));
+        return AST::SwitchCase({ origin->codeLocation,  block->codeLocation()}, WTFMove(*value), WTFMove(*block));
     }
     default: {
-        ASSERT(origin->type == Lexer::Token::Type::Default);
+        ASSERT(origin->type == Token::Type::Default);
         CONSUME_TYPE(colon, Colon);
 
-        PARSE(block, BlockBody, Lexer::Token(*origin));
+        PARSE(block, BlockBody);
 
-        return AST::SwitchCase(WTFMove(*origin), WTF::nullopt, WTFMove(*block));
+        return AST::SwitchCase({ origin->codeLocation,  block->codeLocation()}, WTF::nullopt, WTFMove(*block));
     }
     }
 }
@@ -1122,7 +1151,7 @@ auto Parser::parseForLoop() -> Expected<AST::ForLoop, Error>
         CONSUME_TYPE(semicolon, Semicolon);
 
         Optional<UniqueRef<AST::Expression>> condition = WTF::nullopt;
-        if (!tryType(Lexer::Token::Type::Semicolon)) {
+        if (!tryType(Token::Type::Semicolon)) {
             if (auto expression = parseExpression())
                 condition = { WTFMove(*expression) };
             else
@@ -1131,7 +1160,7 @@ auto Parser::parseForLoop() -> Expected<AST::ForLoop, Error>
         }
 
         Optional<UniqueRef<AST::Expression>> increment = WTF::nullopt;
-        if (!tryType(Lexer::Token::Type::RightParenthesis)) {
+        if (!tryType(Token::Type::RightParenthesis)) {
             if (auto expression = parseExpression())
                 increment = { WTFMove(*expression) };
             else
@@ -1140,8 +1169,8 @@ auto Parser::parseForLoop() -> Expected<AST::ForLoop, Error>
         }
 
         PARSE(body, Statement);
-
-        return AST::ForLoop(WTFMove(*origin), WTFMove(initialization), WTFMove(condition), WTFMove(increment), WTFMove(*body));
+        AST::CodeLocation location(origin->codeLocation,  (*body)->codeLocation());
+        return AST::ForLoop(location, WTFMove(initialization), WTFMove(condition), WTFMove(increment), WTFMove(*body));
     };
 
     auto variableDeclarations = backtrackingScope<Expected<AST::VariableDeclarationsStatement, Error>>([&]() {
@@ -1165,7 +1194,8 @@ auto Parser::parseWhileLoop() -> Expected<AST::WhileLoop, Error>
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
     PARSE(body, Statement);
 
-    return AST::WhileLoop(WTFMove(*origin), WTFMove(*conditional), WTFMove(*body));
+    AST::CodeLocation location(origin->codeLocation,  (*body)->codeLocation());
+    return AST::WhileLoop(location, WTFMove(*conditional), WTFMove(*body));
 }
 
 auto Parser::parseDoWhileLoop() -> Expected<AST::DoWhileLoop, Error>
@@ -1178,7 +1208,7 @@ auto Parser::parseDoWhileLoop() -> Expected<AST::DoWhileLoop, Error>
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
     CONSUME_TYPE(semicolon, Semicolon);
 
-    return AST::DoWhileLoop(WTFMove(*origin), WTFMove(*body), WTFMove(*conditional));
+    return AST::DoWhileLoop({ *origin, *semicolon}, WTFMove(*body), WTFMove(*conditional));
 }
 
 auto Parser::parseVariableDeclaration(UniqueRef<AST::UnnamedType>&& type) -> Expected<AST::VariableDeclaration, Error>
@@ -1191,12 +1221,13 @@ auto Parser::parseVariableDeclaration(UniqueRef<AST::UnnamedType>&& type) -> Exp
     PARSE(semantic, Semantic);
 
     std::unique_ptr<AST::Expression> initializer = nullptr;
-    if (tryType(Lexer::Token::Type::EqualsSign)) {
+    if (tryType(Token::Type::EqualsSign)) {
         PARSE(initializingExpression, PossibleTernaryConditional);
         initializer = initializingExpression.value().moveToUniquePtr();
     }
 
-    return AST::VariableDeclaration(WTFMove(*origin), WTFMove(qualifiers), { WTFMove(type) }, name->stringView(m_lexer).toString(), WTFMove(*semantic), WTFMove(initializer));
+    auto endOffset = m_lexer.peek().startOffset();
+    return AST::VariableDeclaration({ origin->startOffset(), endOffset }, WTFMove(qualifiers), { WTFMove(type) }, name->stringView(m_lexer).toString(), WTFMove(*semantic), WTFMove(initializer));
 }
 
 auto Parser::parseVariableDeclarations() -> Expected<AST::VariableDeclarationsStatement, Error>
@@ -1212,71 +1243,72 @@ auto Parser::parseVariableDeclarations() -> Expected<AST::VariableDeclarationsSt
     Vector<UniqueRef<AST::VariableDeclaration>> result;
     result.append(makeUniqueRef<AST::VariableDeclaration>(WTFMove(*firstVariableDeclaration)));
 
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         auto variableDeclaration = parseVariableDeclaration((*type)->clone());
         if (!variableDeclaration)
             return Unexpected<Error>(variableDeclaration.error());
         result.append(makeUniqueRef<AST::VariableDeclaration>(WTFMove(*variableDeclaration)));
     }
 
-    return AST::VariableDeclarationsStatement(WTFMove(*origin), WTFMove(result));
+    auto endOffset = m_lexer.peek().startOffset();
+    return AST::VariableDeclarationsStatement({ origin->startOffset(), endOffset }, WTFMove(result));
 }
 
 auto Parser::parseStatement() -> Expected<UniqueRef<AST::Statement>, Error>
 {
     PEEK(token);
     switch (token->type) {
-    case Lexer::Token::Type::LeftCurlyBracket: {
+    case Token::Type::LeftCurlyBracket: {
         PARSE(block, Block);
         return { makeUniqueRef<AST::Block>(WTFMove(*block)) };
     }
-    case Lexer::Token::Type::If: {
+    case Token::Type::If: {
         PARSE(ifStatement, IfStatement);
         return { makeUniqueRef<AST::IfStatement>(WTFMove(*ifStatement)) };
     }
-    case Lexer::Token::Type::Switch: {
+    case Token::Type::Switch: {
         PARSE(switchStatement, SwitchStatement);
         return { makeUniqueRef<AST::SwitchStatement>(WTFMove(*switchStatement)) };
     }
-    case Lexer::Token::Type::For: {
+    case Token::Type::For: {
         PARSE(forLoop, ForLoop);
         return { makeUniqueRef<AST::ForLoop>(WTFMove(*forLoop)) };
     }
-    case Lexer::Token::Type::While: {
+    case Token::Type::While: {
         PARSE(whileLoop, WhileLoop);
         return { makeUniqueRef<AST::WhileLoop>(WTFMove(*whileLoop)) };
     }
-    case Lexer::Token::Type::Do: {
+    case Token::Type::Do: {
         PARSE(doWhileLoop, DoWhileLoop);
         return { makeUniqueRef<AST::DoWhileLoop>(WTFMove(*doWhileLoop)) };
     }
-    case Lexer::Token::Type::Break: {
+    case Token::Type::Break: {
         auto breakToken = m_lexer.consumeToken();
         CONSUME_TYPE(semicolon, Semicolon);
         auto breakObject = AST::Break(WTFMove(breakToken));
         return { makeUniqueRef<AST::Break>(WTFMove(breakObject)) };
     }
-    case Lexer::Token::Type::Continue: {
+    case Token::Type::Continue: {
         auto continueToken = m_lexer.consumeToken();
         CONSUME_TYPE(semicolon, Semicolon);
         auto continueObject = AST::Continue(WTFMove(continueToken));
         return { makeUniqueRef<AST::Continue>(WTFMove(continueObject)) };
     }
-    case Lexer::Token::Type::Fallthrough: {
+    case Token::Type::Fallthrough: {
         auto fallthroughToken = m_lexer.consumeToken();
         CONSUME_TYPE(semicolon, Semicolon);
         auto fallthroughObject = AST::Fallthrough(WTFMove(fallthroughToken));
         return { makeUniqueRef<AST::Fallthrough>(WTFMove(fallthroughObject)) };
     }
-    case Lexer::Token::Type::Trap: {
+    case Token::Type::Trap: {
         auto trapToken = m_lexer.consumeToken();
         CONSUME_TYPE(semicolon, Semicolon);
         auto trapObject = AST::Trap(WTFMove(trapToken));
         return { makeUniqueRef<AST::Trap>(WTFMove(trapObject)) };
     }
-    case Lexer::Token::Type::Return: {
+    case Token::Type::Return: {
         auto returnToken = m_lexer.consumeToken();
-        if (auto semicolon = tryType(Lexer::Token::Type::Semicolon)) {
+        if (auto semicolon = tryType(Token::Type::Semicolon)) {
             auto returnObject = AST::Return(WTFMove(returnToken), WTF::nullopt);
             return { makeUniqueRef<AST::Return>(WTFMove(returnObject)) };
         }
@@ -1285,21 +1317,21 @@ auto Parser::parseStatement() -> Expected<UniqueRef<AST::Statement>, Error>
         auto returnObject = AST::Return(WTFMove(returnToken), { WTFMove(*expression) });
         return { makeUniqueRef<AST::Return>(WTFMove(returnObject)) };
     }
-    case Lexer::Token::Type::Constant:
-    case Lexer::Token::Type::Device:
-    case Lexer::Token::Type::Threadgroup:
-    case Lexer::Token::Type::Thread: {
+    case Token::Type::Constant:
+    case Token::Type::Device:
+    case Token::Type::Threadgroup:
+    case Token::Type::Thread: {
         PARSE(variableDeclarations, VariableDeclarations);
         CONSUME_TYPE(semicolon, Semicolon);
         return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) };
     }
-    case Lexer::Token::Type::Identifier: {
+    case Token::Type::Identifier: {
         PEEK_FURTHER(nextToken);
         switch (nextToken->type) {
-        case Lexer::Token::Type::Identifier:
-        case Lexer::Token::Type::LessThanSign:
-        case Lexer::Token::Type::Star:
-        case Lexer::Token::Type::Qualifier: {
+        case Token::Type::Identifier:
+        case Token::Type::LessThanSign:
+        case Token::Type::Star:
+        case Token::Type::Qualifier: {
             PARSE(variableDeclarations, VariableDeclarations);
             CONSUME_TYPE(semicolon, Semicolon);
             return { makeUniqueRef<AST::VariableDeclarationsStatement>(WTFMove(*variableDeclarations)) };
@@ -1331,22 +1363,23 @@ auto Parser::parseStatement() -> Expected<UniqueRef<AST::Statement>, Error>
 auto Parser::parseEffectfulExpression() -> Expected<UniqueRef<AST::Expression>, Error>
 {
     PEEK(origin);
-
     Vector<UniqueRef<AST::Expression>> expressions;
-    if (origin->type == Lexer::Token::Type::Semicolon)
-        return { makeUniqueRef<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions)) };
+    if (origin->type == Token::Type::Semicolon)
+        return { makeUniqueRef<AST::CommaExpression>(*origin, WTFMove(expressions)) };
 
     PARSE(effectfulExpression, EffectfulAssignment);
     expressions.append(WTFMove(*effectfulExpression));
 
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         PARSE(expression, EffectfulAssignment);
         expressions.append(WTFMove(*expression));
     }
 
     if (expressions.size() == 1)
         return WTFMove(expressions[0]);
-    return { makeUniqueRef<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions)) };
+    unsigned endOffset = m_lexer.peek().startOffset();
+    AST::CodeLocation location(origin->startOffset(), endOffset);
+    return { makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)) };
 }
 
 auto Parser::parseEffectfulAssignment() -> Expected<UniqueRef<AST::Expression>, Error>
@@ -1357,19 +1390,19 @@ auto Parser::parseEffectfulAssignment() -> Expected<UniqueRef<AST::Expression>,
     PARSE(expression, PossiblePrefix, &isEffectful);
 
     if (!isEffectful || peekTypes<
-        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
+        Token::Type::EqualsSign,
+        Token::Type::PlusEquals,
+        Token::Type::MinusEquals,
+        Token::Type::TimesEquals,
+        Token::Type::DivideEquals,
+        Token::Type::ModEquals,
+        Token::Type::XorEquals,
+        Token::Type::AndEquals,
+        Token::Type::OrEquals,
+        Token::Type::RightShiftEquals,
+        Token::Type::LeftShiftEquals
     >()) {
-        return completeAssignment(WTFMove(*origin), WTFMove(*expression));
+        return completeAssignment(WTFMove(*expression));
     }
 
     return expression;
@@ -1378,33 +1411,37 @@ auto Parser::parseEffectfulAssignment() -> Expected<UniqueRef<AST::Expression>,
 auto Parser::parseLimitedSuffixOperator(UniqueRef<AST::Expression>&& previous) -> SuffixExpression
 {
     auto type = consumeTypes<
-        Lexer::Token::Type::FullStop,
-        Lexer::Token::Type::Arrow,
-        Lexer::Token::Type::LeftSquareBracket>();
+        Token::Type::FullStop,
+        Token::Type::Arrow,
+        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);
+    case Token::Type::FullStop: {
+        auto identifier = consumeType(Token::Type::Identifier);
         if (!identifier)
             return SuffixExpression(WTFMove(previous), false);
-        return SuffixExpression(makeUniqueRef<AST::DotExpression>(WTFMove(*type), WTFMove(previous), identifier->stringView(m_lexer).toString()), true);
+        AST::CodeLocation location(previous->codeLocation(), *identifier);
+        return SuffixExpression(makeUniqueRef<AST::DotExpression>(location, WTFMove(previous), identifier->stringView(m_lexer).toString()), true);
     }
-    case Lexer::Token::Type::Arrow: {
-        auto identifier = consumeType(Lexer::Token::Type::Identifier);
+    case Token::Type::Arrow: {
+        auto identifier = consumeType(Token::Type::Identifier);
         if (!identifier)
             return SuffixExpression(WTFMove(previous), false);
-        return SuffixExpression(makeUniqueRef<AST::DotExpression>(Lexer::Token(*type), makeUniqueRef<AST::DereferenceExpression>(WTFMove(*type), WTFMove(previous)), identifier->stringView(m_lexer).toString()), true);
+        AST::CodeLocation location(previous->codeLocation(), *identifier);
+        return SuffixExpression(makeUniqueRef<AST::DotExpression>(location, makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(previous)), identifier->stringView(m_lexer).toString()), true);
     }
     default: {
-        ASSERT(type->type == Lexer::Token::Type::LeftSquareBracket);
+        ASSERT(type->type == 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(makeUniqueRef<AST::IndexExpression>(WTFMove(*type), WTFMove(previous), WTFMove(*expression)), true);
+        if (auto rightSquareBracket = consumeType(Token::Type::RightSquareBracket)) {
+            AST::CodeLocation location(previous->codeLocation(), *rightSquareBracket);
+            return SuffixExpression(makeUniqueRef<AST::IndexExpression>(location, WTFMove(previous), WTFMove(*expression)), true);
+        }
+        return SuffixExpression(WTFMove(previous), false);
     }
     }
 }
@@ -1412,49 +1449,55 @@ auto Parser::parseLimitedSuffixOperator(UniqueRef<AST::Expression>&& previous) -
 auto Parser::parseSuffixOperator(UniqueRef<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>();
+        Token::Type::FullStop,
+        Token::Type::Arrow,
+        Token::Type::LeftSquareBracket,
+        Token::Type::PlusPlus,
+        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);
+    case Token::Type::FullStop: {
+        auto identifier = consumeType(Token::Type::Identifier);
         if (!identifier)
             return SuffixExpression(WTFMove(previous), false);
-        return SuffixExpression(makeUniqueRef<AST::DotExpression>(WTFMove(*suffix), WTFMove(previous), identifier->stringView(m_lexer).toString()), true);
+        AST::CodeLocation location(previous->codeLocation(), *identifier);
+        return SuffixExpression(makeUniqueRef<AST::DotExpression>(location, WTFMove(previous), identifier->stringView(m_lexer).toString()), true);
     }
-    case Lexer::Token::Type::Arrow: {
-        auto identifier = consumeType(Lexer::Token::Type::Identifier);
+    case Token::Type::Arrow: {
+        auto identifier = consumeType(Token::Type::Identifier);
         if (!identifier)
             return SuffixExpression(WTFMove(previous), false);
-        return SuffixExpression(makeUniqueRef<AST::DotExpression>(Lexer::Token(*suffix), makeUniqueRef<AST::DereferenceExpression>(WTFMove(*suffix), WTFMove(previous)), identifier->stringView(m_lexer).toString()), true);
+        AST::CodeLocation location(previous->codeLocation(), *identifier);
+        return SuffixExpression(makeUniqueRef<AST::DotExpression>(location, makeUniqueRef<AST::DereferenceExpression>(WTFMove(*suffix), WTFMove(previous)), identifier->stringView(m_lexer).toString()), true);
     }
-    case Lexer::Token::Type::LeftSquareBracket: {
+    case 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(makeUniqueRef<AST::IndexExpression>(WTFMove(*suffix), WTFMove(previous), WTFMove(*expression)), true);
+        if (auto rightSquareBracket = consumeType(Token::Type::RightSquareBracket)) {
+            AST::CodeLocation location(previous->codeLocation(), *rightSquareBracket);
+            return SuffixExpression(makeUniqueRef<AST::IndexExpression>(location, WTFMove(previous), WTFMove(*expression)), true);
+        }
+        return SuffixExpression(WTFMove(previous), false);
     }
-    case Lexer::Token::Type::PlusPlus: {
-        auto result = AST::ReadModifyWriteExpression::create(Lexer::Token(*suffix), WTFMove(previous));
+    case Token::Type::PlusPlus: {
+        AST::CodeLocation location(previous->codeLocation(), *suffix);
+        auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(previous));
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(result->oldVariableReference());
-        result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(WTFMove(*suffix), "operator++"_str, WTFMove(callArguments)));
+        result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator++"_str, WTFMove(callArguments)));
         result->setResultExpression(result->oldVariableReference());
         return SuffixExpression(WTFMove(result), true);
     }
     default: {
-        ASSERT(suffix->type == Lexer::Token::Type::MinusMinus);
-        auto result = AST::ReadModifyWriteExpression::create(Lexer::Token(*suffix), WTFMove(previous));
+        ASSERT(suffix->type == Token::Type::MinusMinus);
+        AST::CodeLocation location(previous->codeLocation(), *suffix);
+        auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(previous));
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(result->oldVariableReference());
-        result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(WTFMove(*suffix), "operator--"_str, WTFMove(callArguments)));
+        result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator--"_str, WTFMove(callArguments)));
         result->setResultExpression(result->oldVariableReference());
         return SuffixExpression(WTFMove(result), true);
     }
@@ -1463,119 +1506,121 @@ auto Parser::parseSuffixOperator(UniqueRef<AST::Expression>&& previous) -> Suffi
 
 auto Parser::parseExpression() -> Expected<UniqueRef<AST::Expression>, Error>
 {
-    PEEK(origin);
-
     PARSE(first, PossibleTernaryConditional);
     Vector<UniqueRef<AST::Expression>> expressions;
+    unsigned startOffset = (*first)->codeLocation().startOffset();
     expressions.append(WTFMove(*first));
 
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         PARSE(expression, PossibleTernaryConditional);
         expressions.append(WTFMove(*expression));
     }
 
     if (expressions.size() == 1)
         return WTFMove(expressions[0]);
-    return { makeUniqueRef<AST::CommaExpression>(WTFMove(*origin), WTFMove(expressions)) };
+    auto endOffset = m_lexer.peek().startOffset();
+    AST::CodeLocation location(startOffset, endOffset);
+    return { makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions)) };
 }
 
-auto Parser::completeTernaryConditional(Lexer::Token&& origin, UniqueRef<AST::Expression>&& predicate) -> Expected<UniqueRef<AST::Expression>, Error>
+auto Parser::completeTernaryConditional(UniqueRef<AST::Expression>&& predicate) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     CONSUME_TYPE(questionMark, QuestionMark);
     PARSE(bodyExpression, Expression);
     CONSUME_TYPE(colon, Colon);
     PARSE(elseExpression, PossibleTernaryConditional);
 
+    AST::CodeLocation predicateLocation = predicate->codeLocation();
     Vector<UniqueRef<AST::Expression>> castArguments;
     castArguments.append(WTFMove(predicate));
-    auto boolCast = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), "bool"_str, WTFMove(castArguments));
-    return { makeUniqueRef<AST::TernaryExpression>(WTFMove(origin), WTFMove(boolCast), WTFMove(*bodyExpression), WTFMove(*elseExpression)) };
+    auto boolCast = makeUniqueRef<AST::CallExpression>(predicateLocation, "bool"_str, WTFMove(castArguments));
+    AST::CodeLocation location(predicateLocation, (*elseExpression)->codeLocation());
+    return { makeUniqueRef<AST::TernaryExpression>(location, WTFMove(boolCast), WTFMove(*bodyExpression), WTFMove(*elseExpression)) };
 }
 
-auto Parser::completeAssignment(Lexer::Token&& origin, UniqueRef<AST::Expression>&& left) -> Expected<UniqueRef<AST::Expression>, Error>
+auto Parser::completeAssignment(UniqueRef<AST::Expression>&& left) -> Expected<UniqueRef<AST::Expression>, 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>();
+        Token::Type::EqualsSign,
+        Token::Type::PlusEquals,
+        Token::Type::MinusEquals,
+        Token::Type::TimesEquals,
+        Token::Type::DivideEquals,
+        Token::Type::ModEquals,
+        Token::Type::XorEquals,
+        Token::Type::AndEquals,
+        Token::Type::OrEquals,
+        Token::Type::RightShiftEquals,
+        Token::Type::LeftShiftEquals>();
     if (!assignmentOperator)
         return Unexpected<Error>(assignmentOperator.error());
 
     PARSE(right, PossibleTernaryConditional);
+    AST::CodeLocation location = { left->codeLocation(), (*right)->codeLocation() };
 
-    if (assignmentOperator->type == Lexer::Token::Type::EqualsSign)
-        return { makeUniqueRef<AST::AssignmentExpression>(WTFMove(origin), WTFMove(left), WTFMove(*right))};
+    if (assignmentOperator->type == Token::Type::EqualsSign)
+        return { makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(left), WTFMove(*right))};
 
     String name;
     switch (assignmentOperator->type) {
-    case Lexer::Token::Type::PlusEquals:
+    case Token::Type::PlusEquals:
         name = "operator+"_str;
         break;
-    case Lexer::Token::Type::MinusEquals:
+    case Token::Type::MinusEquals:
         name = "operator-"_str;
         break;
-    case Lexer::Token::Type::TimesEquals:
+    case Token::Type::TimesEquals:
         name = "operator*"_str;
         break;
-    case Lexer::Token::Type::DivideEquals:
+    case Token::Type::DivideEquals:
         name = "operator/"_str;
         break;
-    case Lexer::Token::Type::ModEquals:
+    case Token::Type::ModEquals:
         name = "operator%"_str;
         break;
-    case Lexer::Token::Type::XorEquals:
+    case Token::Type::XorEquals:
         name = "operator^"_str;
         break;
-    case Lexer::Token::Type::AndEquals:
+    case Token::Type::AndEquals:
         name = "operator&"_str;
         break;
-    case Lexer::Token::Type::OrEquals:
+    case Token::Type::OrEquals:
         name = "operator|"_str;
         break;
-    case Lexer::Token::Type::RightShiftEquals:
+    case Token::Type::RightShiftEquals:
         name = "operator>>"_str;
         break;
     default:
-        ASSERT(assignmentOperator->type == Lexer::Token::Type::LeftShiftEquals);
+        ASSERT(assignmentOperator->type == Token::Type::LeftShiftEquals);
         name = "operator<<"_str;
         break;
     }
 
-    auto result = AST::ReadModifyWriteExpression::create(Lexer::Token(origin), WTFMove(left));
+    auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(left));
     Vector<UniqueRef<AST::Expression>> callArguments;
     callArguments.append(result->oldVariableReference());
     callArguments.append(WTFMove(*right));
-    result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(WTFMove(origin), WTFMove(name), WTFMove(callArguments)));
+    result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, WTFMove(name), WTFMove(callArguments)));
     result->setResultExpression(result->newVariableReference());
     return { WTFMove(result) };
 }
 
 auto Parser::parsePossibleTernaryConditional() -> Expected<UniqueRef<AST::Expression>, Error>
 {
-    PEEK(origin);
-
     PARSE(expression, PossiblePrefix);
 
-    if (peekTypes<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>()) {
-        return completeAssignment(WTFMove(*origin), WTFMove(*expression));
+    if (peekTypes<Token::Type::EqualsSign,
+        Token::Type::PlusEquals,
+        Token::Type::MinusEquals,
+        Token::Type::TimesEquals,
+        Token::Type::DivideEquals,
+        Token::Type::ModEquals,
+        Token::Type::XorEquals,
+        Token::Type::AndEquals,
+        Token::Type::OrEquals,
+        Token::Type::RightShiftEquals,
+        Token::Type::LeftShiftEquals>()) {
+        return completeAssignment(WTFMove(*expression));
     }
 
     expression = completePossibleShift(WTFMove(*expression));
@@ -1585,8 +1630,8 @@ auto Parser::parsePossibleTernaryConditional() -> Expected<UniqueRef<AST::Expres
     expression = completePossibleLogicalBinaryOperation(WTFMove(*expression));
 
     PEEK(nextToken);
-    if (nextToken->type == Lexer::Token::Type::QuestionMark)
-        return completeTernaryConditional(WTFMove(*origin), WTFMove(*expression));
+    if (nextToken->type == Token::Type::QuestionMark)
+        return completeTernaryConditional(WTFMove(*expression));
     return expression;
 }
 
@@ -1599,41 +1644,42 @@ auto Parser::parsePossibleLogicalBinaryOperation() -> Expected<UniqueRef<AST::Ex
 auto Parser::completePossibleLogicalBinaryOperation(UniqueRef<AST::Expression>&& previous) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     while (auto logicalBinaryOperation = tryTypes<
-        Lexer::Token::Type::OrOr,
-        Lexer::Token::Type::AndAnd,
-        Lexer::Token::Type::Or,
-        Lexer::Token::Type::Xor,
-        Lexer::Token::Type::And
+        Token::Type::OrOr,
+        Token::Type::AndAnd,
+        Token::Type::Or,
+        Token::Type::Xor,
+        Token::Type::And
         >()) {
         PARSE(next, PossibleRelationalBinaryOperation);
+        AST::CodeLocation location(previous->codeLocation(), (*next)->codeLocation());
 
         switch (logicalBinaryOperation->type) {
-        case Lexer::Token::Type::OrOr:
-            previous = makeUniqueRef<AST::LogicalExpression>(WTFMove(*logicalBinaryOperation), AST::LogicalExpression::Type::Or, WTFMove(previous), WTFMove(*next));
+        case Token::Type::OrOr:
+            previous = makeUniqueRef<AST::LogicalExpression>(location, AST::LogicalExpression::Type::Or, WTFMove(previous), WTFMove(*next));
             break;
-        case Lexer::Token::Type::AndAnd:
-            previous = makeUniqueRef<AST::LogicalExpression>(WTFMove(*logicalBinaryOperation), AST::LogicalExpression::Type::And, WTFMove(previous), WTFMove(*next));
+        case Token::Type::AndAnd:
+            previous = makeUniqueRef<AST::LogicalExpression>(location, AST::LogicalExpression::Type::And, WTFMove(previous), WTFMove(*next));
             break;
-        case Lexer::Token::Type::Or: {
+        case Token::Type::Or: {
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(previous));
             callArguments.append(WTFMove(*next));
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*logicalBinaryOperation), "operator|"_str, WTFMove(callArguments));
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator|"_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::Xor: {
+        case Token::Type::Xor: {
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(previous));
             callArguments.append(WTFMove(*next));
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*logicalBinaryOperation), "operator^"_str, WTFMove(callArguments));
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator^"_str, WTFMove(callArguments));
             break;
         }
         default: {
-            ASSERT(logicalBinaryOperation->type == Lexer::Token::Type::And);
+            ASSERT(logicalBinaryOperation->type == Token::Type::And);
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(previous));
             callArguments.append(WTFMove(*next));
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*logicalBinaryOperation), "operator&"_str, WTFMove(callArguments));
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator&"_str, WTFMove(callArguments));
             break;
         }
         }
@@ -1651,44 +1697,45 @@ auto Parser::parsePossibleRelationalBinaryOperation() -> Expected<UniqueRef<AST:
 auto Parser::completePossibleRelationalBinaryOperation(UniqueRef<AST::Expression>&& previous) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     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
+        Token::Type::LessThanSign,
+        Token::Type::GreaterThanSign,
+        Token::Type::LessThanOrEqualTo,
+        Token::Type::GreaterThanOrEqualTo,
+        Token::Type::EqualComparison,
+        Token::Type::NotEqual
         >()) {
         PARSE(next, PossibleShift);
+        AST::CodeLocation location(previous->codeLocation(), (*next)->codeLocation());
 
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(WTFMove(previous));
         callArguments.append(WTFMove(*next));
 
         switch (relationalBinaryOperation->type) {
-        case Lexer::Token::Type::LessThanSign: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*relationalBinaryOperation), "operator<"_str, WTFMove(callArguments));
+        case Token::Type::LessThanSign: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator<"_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::GreaterThanSign: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*relationalBinaryOperation), "operator>"_str, WTFMove(callArguments));
+        case Token::Type::GreaterThanSign: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator>"_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::LessThanOrEqualTo: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*relationalBinaryOperation), "operator<="_str, WTFMove(callArguments));
+        case Token::Type::LessThanOrEqualTo: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator<="_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::GreaterThanOrEqualTo: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*relationalBinaryOperation), "operator>="_str, WTFMove(callArguments));
+        case Token::Type::GreaterThanOrEqualTo: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator>="_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::EqualComparison: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*relationalBinaryOperation), "operator=="_str, WTFMove(callArguments));
+        case Token::Type::EqualComparison: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator=="_str, WTFMove(callArguments));
             break;
         }
         default: {
-            ASSERT(relationalBinaryOperation->type == Lexer::Token::Type::NotEqual);
-            previous = makeUniqueRef<AST::CallExpression>(Lexer::Token(*relationalBinaryOperation), "operator=="_str, WTFMove(callArguments));
-            previous = makeUniqueRef<AST::LogicalNotExpression>(WTFMove(*relationalBinaryOperation), WTFMove(previous));
+            ASSERT(relationalBinaryOperation->type == Token::Type::NotEqual);
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator=="_str, WTFMove(callArguments));
+            previous = makeUniqueRef<AST::LogicalNotExpression>(location, WTFMove(previous));
             break;
         }
         }
@@ -1706,23 +1753,24 @@ auto Parser::parsePossibleShift() -> Expected<UniqueRef<AST::Expression>, Error>
 auto Parser::completePossibleShift(UniqueRef<AST::Expression>&& previous) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     while (auto shift = tryTypes<
-        Lexer::Token::Type::LeftShift,
-        Lexer::Token::Type::RightShift
+        Token::Type::LeftShift,
+        Token::Type::RightShift
         >()) {
         PARSE(next, PossibleAdd);
+        AST::CodeLocation location(previous->codeLocation(), (*next)->codeLocation());
 
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(WTFMove(previous));
         callArguments.append(WTFMove(*next));
 
         switch (shift->type) {
-        case Lexer::Token::Type::LeftShift: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*shift), "operator<<"_str, WTFMove(callArguments));
+        case Token::Type::LeftShift: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator<<"_str, WTFMove(callArguments));
             break;
         }
         default: {
-            ASSERT(shift->type == Lexer::Token::Type::RightShift);
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*shift), "operator>>"_str, WTFMove(callArguments));
+            ASSERT(shift->type == Token::Type::RightShift);
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator>>"_str, WTFMove(callArguments));
             break;
         }
         }
@@ -1740,23 +1788,24 @@ auto Parser::parsePossibleAdd() -> Expected<UniqueRef<AST::Expression>, Error>
 auto Parser::completePossibleAdd(UniqueRef<AST::Expression>&& previous) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     while (auto add = tryTypes<
-        Lexer::Token::Type::Plus,
-        Lexer::Token::Type::Minus
+        Token::Type::Plus,
+        Token::Type::Minus
         >()) {
         PARSE(next, PossibleMultiply);
+        AST::CodeLocation location(previous->codeLocation(), (*next)->codeLocation());
 
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(WTFMove(previous));
         callArguments.append(WTFMove(*next));
 
         switch (add->type) {
-        case Lexer::Token::Type::Plus: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*add), "operator+"_str, WTFMove(callArguments));
+        case Token::Type::Plus: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator+"_str, WTFMove(callArguments));
             break;
         }
         default: {
-            ASSERT(add->type == Lexer::Token::Type::Minus);
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*add), "operator-"_str, WTFMove(callArguments));
+            ASSERT(add->type == Token::Type::Minus);
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator-"_str, WTFMove(callArguments));
             break;
         }
         }
@@ -1774,28 +1823,29 @@ auto Parser::parsePossibleMultiply() -> Expected<UniqueRef<AST::Expression>, Err
 auto Parser::completePossibleMultiply(UniqueRef<AST::Expression>&& previous) -> Expected<UniqueRef<AST::Expression>, Error>
 {
     while (auto multiply = tryTypes<
-        Lexer::Token::Type::Star,
-        Lexer::Token::Type::Divide,
-        Lexer::Token::Type::Mod
+        Token::Type::Star,
+        Token::Type::Divide,
+        Token::Type::Mod
         >()) {
         PARSE(next, PossiblePrefix);
+        AST::CodeLocation location(previous->codeLocation(), (*next)->codeLocation());
 
         Vector<UniqueRef<AST::Expression>> callArguments;
         callArguments.append(WTFMove(previous));
         callArguments.append(WTFMove(*next));
 
         switch (multiply->type) {
-        case Lexer::Token::Type::Star: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*multiply), "operator*"_str, WTFMove(callArguments));
+        case Token::Type::Star: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator*"_str, WTFMove(callArguments));
             break;
         }
-        case Lexer::Token::Type::Divide: {
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*multiply), "operator/"_str, WTFMove(callArguments));
+        case Token::Type::Divide: {
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator/"_str, WTFMove(callArguments));
             break;
         }
         default: {
-            ASSERT(multiply->type == Lexer::Token::Type::Mod);
-            previous = makeUniqueRef<AST::CallExpression>(WTFMove(*multiply), "operator%"_str, WTFMove(callArguments));
+            ASSERT(multiply->type == Token::Type::Mod);
+            previous = makeUniqueRef<AST::CallExpression>(location, "operator%"_str, WTFMove(callArguments));
             break;
         }
         }
@@ -1807,67 +1857,68 @@ auto Parser::completePossibleMultiply(UniqueRef<AST::Expression>&& previous) ->
 auto Parser::parsePossiblePrefix(bool *isEffectful) -> Expected<UniqueRef<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
+        Token::Type::PlusPlus,
+        Token::Type::MinusMinus,
+        Token::Type::Plus,
+        Token::Type::Minus,
+        Token::Type::Tilde,
+        Token::Type::ExclamationPoint,
+        Token::Type::And,
+        Token::Type::At,
+        Token::Type::Star
     >()) {
         PARSE(next, PossiblePrefix);
+        AST::CodeLocation location(*prefix, (*next)->codeLocation());
 
         switch (prefix->type) {
-        case Lexer::Token::Type::PlusPlus: {
+        case Token::Type::PlusPlus: {
             if (isEffectful)
                 *isEffectful = true;
-            auto result = AST::ReadModifyWriteExpression::create(Lexer::Token(*prefix), WTFMove(*next));
+            auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(*next));
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(result->oldVariableReference());
-            result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "operator++"_str, WTFMove(callArguments)));
+            result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator++"_str, WTFMove(callArguments)));
             result->setResultExpression(result->newVariableReference());
             return { WTFMove(result) };
         }
-        case Lexer::Token::Type::MinusMinus: {
+        case Token::Type::MinusMinus: {
             if (isEffectful)
                 *isEffectful = true;
-            auto result = AST::ReadModifyWriteExpression::create(Lexer::Token(*prefix), WTFMove(*next));
+            auto result = AST::ReadModifyWriteExpression::create(location, WTFMove(*next));
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(result->oldVariableReference());
-            result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "operator--"_str, WTFMove(callArguments)));
+            result->setNewValueExpression(makeUniqueRef<AST::CallExpression>(location, "operator--"_str, WTFMove(callArguments)));
             result->setResultExpression(result->newVariableReference());
             return { WTFMove(result) };
         }
-        case Lexer::Token::Type::Plus: {
+        case Token::Type::Plus: {
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(*next));
-            return { makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "operator+"_str, WTFMove(callArguments)) };
+            return { makeUniqueRef<AST::CallExpression>(location, "operator+"_str, WTFMove(callArguments)) };
         }
-        case Lexer::Token::Type::Minus: {
+        case Token::Type::Minus: {
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(*next));
-            return { makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "operator-"_str, WTFMove(callArguments)) };
+            return { makeUniqueRef<AST::CallExpression>(location, "operator-"_str, WTFMove(callArguments)) };
         }
-        case Lexer::Token::Type::Tilde: {
+        case Token::Type::Tilde: {
             Vector<UniqueRef<AST::Expression>> callArguments;
             callArguments.append(WTFMove(*next));
-            return { makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "operator~"_str, WTFMove(callArguments)) };
+            return { makeUniqueRef<AST::CallExpression>(location, "operator~"_str, WTFMove(callArguments)) };
         }
-        case Lexer::Token::Type::ExclamationPoint: {
+        case Token::Type::ExclamationPoint: {
             Vector<UniqueRef<AST::Expression>> castArguments;
             castArguments.append(WTFMove(*next));
-            auto boolCast = makeUniqueRef<AST::CallExpression>(Lexer::Token(*prefix), "bool"_str, WTFMove(castArguments));
-            return { makeUniqueRef<AST::LogicalNotExpression>(Lexer::Token(*prefix), WTFMove(boolCast)) };
+            auto boolCast = makeUniqueRef<AST::CallExpression>(location, "bool"_str, WTFMove(castArguments));
+            return { makeUniqueRef<AST::LogicalNotExpression>(location, WTFMove(boolCast)) };
         }
-        case Lexer::Token::Type::And:
-            return { makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(*prefix), WTFMove(*next)) };
-        case Lexer::Token::Type::At:
-            return { makeUniqueRef<AST::MakeArrayReferenceExpression>(Lexer::Token(*prefix), WTFMove(*next)) };
+        case Token::Type::And:
+            return { makeUniqueRef<AST::MakePointerExpression>(location, WTFMove(*next)) };
+        case Token::Type::At:
+            return { makeUniqueRef<AST::MakeArrayReferenceExpression>(location, WTFMove(*next)) };
         default:
-            ASSERT(prefix->type == Lexer::Token::Type::Star);
-            return { makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(*prefix), WTFMove(*next)) };
+            ASSERT(prefix->type == Token::Type::Star);
+            return { makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(*next)) };
         }
     }
 
@@ -1879,13 +1930,13 @@ auto Parser::parsePossibleSuffix(bool *isEffectful) -> Expected<UniqueRef<AST::E
     PEEK(token);
     PEEK_FURTHER(nextToken);
 
-    if (token->type == Lexer::Token::Type::Identifier && nextToken->type == Lexer::Token::Type::LeftParenthesis) {
+    if (token->type == Token::Type::Identifier && nextToken->type == Token::Type::LeftParenthesis) {
         PARSE(expression, CallExpression);
         if (isEffectful)
             *isEffectful = true;
         while (true) {
             PEEK(suffixToken);
-            if (suffixToken->type != Lexer::Token::Type::FullStop && suffixToken->type != Lexer::Token::Type::Arrow && suffixToken->type != Lexer::Token::Type::LeftSquareBracket)
+            if (suffixToken->type != Token::Type::FullStop && suffixToken->type != Token::Type::Arrow && suffixToken->type != Token::Type::LeftSquareBracket)
                 break;
             auto result = parseLimitedSuffixOperator(WTFMove(*expression));
             expression = WTFMove(result.result);
@@ -1893,21 +1944,21 @@ auto Parser::parsePossibleSuffix(bool *isEffectful) -> Expected<UniqueRef<AST::E
         return expression;
     }
 
-    if (token->type == Lexer::Token::Type::LeftParenthesis && isEffectful)
+    if (token->type == Token::Type::LeftParenthesis && isEffectful)
         *isEffectful = true;
 
     PARSE(expression, Term);
     bool isLastSuffixTokenEffectful = false;
     while (true) {
         PEEK(suffixToken);
-        if (suffixToken->type != Lexer::Token::Type::FullStop
-            && suffixToken->type != Lexer::Token::Type::Arrow
-            && suffixToken->type != Lexer::Token::Type::LeftSquareBracket
-            && suffixToken->type != Lexer::Token::Type::PlusPlus
-            && suffixToken->type != Lexer::Token::Type::MinusMinus) {
+        if (suffixToken->type != Token::Type::FullStop
+            && suffixToken->type != Token::Type::Arrow
+            && suffixToken->type != Token::Type::LeftSquareBracket
+            && suffixToken->type != Token::Type::PlusPlus
+            && suffixToken->type != Token::Type::MinusMinus) {
             break;
         }
-        isLastSuffixTokenEffectful = suffixToken->type == Lexer::Token::Type::PlusPlus || suffixToken->type == Lexer::Token::Type::MinusMinus;
+        isLastSuffixTokenEffectful = suffixToken->type == Token::Type::PlusPlus || suffixToken->type == Token::Type::MinusMinus;
         auto result = parseSuffixOperator(WTFMove(*expression));
         expression = WTFMove(result.result);
     }
@@ -1924,66 +1975,67 @@ auto Parser::parseCallExpression() -> Expected<UniqueRef<AST::Expression>, Error
     CONSUME_TYPE(leftParenthesis, LeftParenthesis);
 
     Vector<UniqueRef<AST::Expression>> arguments;
-    if (tryType(Lexer::Token::Type::RightParenthesis))
+    if (tryType(Token::Type::RightParenthesis))
         return { makeUniqueRef<AST::CallExpression>(WTFMove(*name), WTFMove(callName), WTFMove(arguments)) };
 
     PARSE(firstArgument, PossibleTernaryConditional);
     arguments.append(WTFMove(*firstArgument));
-    while (tryType(Lexer::Token::Type::Comma)) {
+    while (tryType(Token::Type::Comma)) {
         PARSE(argument, PossibleTernaryConditional);
         arguments.append(WTFMove(*argument));
     }
 
     CONSUME_TYPE(rightParenthesis, RightParenthesis);
+    AST::CodeLocation location(*name, *rightParenthesis);
 
-    return { makeUniqueRef<AST::CallExpression>(WTFMove(*name), WTFMove(callName), WTFMove(arguments)) };
+    return { makeUniqueRef<AST::CallExpression>(location, WTFMove(callName), WTFMove(arguments)) };
 }
 
 auto Parser::parseTerm() -> Expected<UniqueRef<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>();
+        Token::Type::IntLiteral,
+        Token::Type::UintLiteral,
+        Token::Type::FloatLiteral,
+        Token::Type::Null,
+        Token::Type::True,
+        Token::Type::False,
+        Token::Type::Identifier,
+        Token::Type::LeftParenthesis>();
     if (!type)
         return Unexpected<Error>(type.error());
 
     switch (type->type) {
-    case Lexer::Token::Type::IntLiteral: {
+    case Token::Type::IntLiteral: {
         auto value = intLiteralToInt(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return { makeUniqueRef<AST::IntegerLiteral>(WTFMove(*type), *value) };
+        return { makeUniqueRef<AST::IntegerLiteral>(*type, *value) };
     }
-    case Lexer::Token::Type::UintLiteral: {
+    case Token::Type::UintLiteral: {
         auto value = uintLiteralToUint(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return { makeUniqueRef<AST::UnsignedIntegerLiteral>(WTFMove(*type), *value) };
+        return { makeUniqueRef<AST::UnsignedIntegerLiteral>(*type, *value) };
     }
-    case Lexer::Token::Type::FloatLiteral: {
+    case Token::Type::FloatLiteral: {
         auto value = floatLiteralToFloat(type->stringView(m_lexer));
         if (!value)
             return Unexpected<Error>(value.error());
-        return { makeUniqueRef<AST::FloatLiteral>(WTFMove(*type), *value) };
-    }
-    case Lexer::Token::Type::Null:
-        return { makeUniqueRef<AST::NullLiteral>(WTFMove(*type)) };
-    case Lexer::Token::Type::True:
-        return { makeUniqueRef<AST::BooleanLiteral>(WTFMove(*type), true) };
-    case Lexer::Token::Type::False:
-        return { makeUniqueRef<AST::BooleanLiteral>(WTFMove(*type), false) };
-    case Lexer::Token::Type::Identifier: {
+        return { makeUniqueRef<AST::FloatLiteral>(*type, *value) };
+    }
+    case Token::Type::Null:
+        return { makeUniqueRef<AST::NullLiteral>(*type) };
+    case Token::Type::True:
+        return { makeUniqueRef<AST::BooleanLiteral>(*type, true) };
+    case Token::Type::False:
+        return { makeUniqueRef<AST::BooleanLiteral>(*type, false) };
+    case Token::Type::Identifier: {
         auto name = type->stringView(m_lexer).toString();
-        return { makeUniqueRef<AST::VariableReference>(WTFMove(*type), WTFMove(name)) };
+        return { makeUniqueRef<AST::VariableReference>(*type, WTFMove(name)) };
     }
     default: {
-        ASSERT(type->type == Lexer::Token::Type::LeftParenthesis);
+        ASSERT(type->type == Token::Type::LeftParenthesis);
         PARSE(expression, Expression);
         CONSUME_TYPE(rightParenthesis, RightParenthesis);
 
index db9961d..400ce66 100644 (file)
@@ -141,16 +141,17 @@ private:
         No
     };
     Unexpected<Error> fail(const String& message, TryToPeek = TryToPeek::Yes);
-    Expected<Lexer::Token, Error> peek();
-    Expected<Lexer::Token, Error> peekFurther();
-    template <Lexer::Token::Type... types>
+    Expected<Token, Error> peek();
+    Expected<Token, Error> peekFurther();
+    bool peekType(Token::Type);
+    template <Token::Type... types>
     bool peekTypes();
-    Optional<Lexer::Token> tryType(Lexer::Token::Type);
-    template <Lexer::Token::Type... types>
-    Optional<Lexer::Token> tryTypes();
-    Expected<Lexer::Token, Error> consumeType(Lexer::Token::Type);
-    template <Lexer::Token::Type... types>
-    Expected<Lexer::Token, Error> consumeTypes();
+    Optional<Token> tryType(Token::Type);
+    template <Token::Type... types>
+    Optional<Token> tryTypes();
+    Expected<Token, Error> consumeType(Token::Type);
+    template <Token::Type... types>
+    Expected<Token, Error> consumeTypes();
 
     Expected<Variant<int, unsigned>, Error> consumeIntegralLiteral();
     Expected<unsigned, Error> consumeNonNegativeIntegralLiteral();
@@ -158,12 +159,14 @@ private:
     Expected<AST::TypeArgument, Error> parseTypeArgument();
     Expected<AST::TypeArguments, Error> parseTypeArguments();
     struct TypeSuffixAbbreviated {
-        Lexer::Token token;
+        AST::CodeLocation location;
+        Token token;
         Optional<unsigned> numElements;
     };
     Expected<TypeSuffixAbbreviated, Error> parseTypeSuffixAbbreviated();
     struct TypeSuffixNonAbbreviated {
-        Lexer::Token token;
+        AST::CodeLocation location;
+        Token token;
         Optional<AST::AddressSpace> addressSpace;
         Optional<unsigned> numElements;
     };
@@ -196,7 +199,7 @@ private:
     Expected<AST::NativeFunctionDeclaration, Error> parseNativeFunctionDeclaration();
 
     Expected<AST::Block, Error> parseBlock();
-    Expected<AST::Block, Error> parseBlockBody(Lexer::Token&& origin);
+    Expected<AST::Block, Error> parseBlockBody();
     Expected<AST::IfStatement, Error> parseIfStatement();
     Expected<AST::SwitchStatement, Error> parseSwitchStatement();
     Expected<AST::SwitchCase, Error> parseSwitchCase();
@@ -225,8 +228,8 @@ private:
 
     Expected<UniqueRef<AST::Expression>, Error> parseExpression();
     Expected<UniqueRef<AST::Expression>, Error> parsePossibleTernaryConditional();
-    Expected<UniqueRef<AST::Expression>, Error> completeTernaryConditional(Lexer::Token&& origin, UniqueRef<AST::Expression>&& predicate);
-    Expected<UniqueRef<AST::Expression>, Error> completeAssignment(Lexer::Token&& origin, UniqueRef<AST::Expression>&& left);
+    Expected<UniqueRef<AST::Expression>, Error> completeTernaryConditional(UniqueRef<AST::Expression>&& predicate);
+    Expected<UniqueRef<AST::Expression>, Error> completeAssignment(UniqueRef<AST::Expression>&& left);
     Expected<UniqueRef<AST::Expression>, Error> parsePossibleLogicalBinaryOperation();
     Expected<UniqueRef<AST::Expression>, Error> completePossibleLogicalBinaryOperation(UniqueRef<AST::Expression>&& previous);
     Expected<UniqueRef<AST::Expression>, Error> parsePossibleRelationalBinaryOperation();
index 9d81efd..1a09581 100644 (file)
@@ -91,9 +91,9 @@ private:
     HashMap<AST::VariableDeclaration*, String> m_escapedVariables;
 };
 
-static ALWAYS_INLINE Lexer::Token anonymousToken(Lexer::Token::Type type)
+static ALWAYS_INLINE Token anonymousToken(Token::Type type)
 {
-    return Lexer::Token { 0, 0, type };
+    return Token { { }, type };
 }
 
 class PreserveLifetimes : public Visitor {
@@ -101,7 +101,7 @@ class PreserveLifetimes : public Visitor {
 public:
     PreserveLifetimes(UniqueRef<AST::TypeReference>& structType, const HashMap<AST::VariableDeclaration*, AST::StructureElement*>& variableMapping)
         : m_structType(structType)
-        , m_pointerToStructType(makeUniqueRef<AST::PointerType>(anonymousToken(Lexer::Token::Type::Identifier), AST::AddressSpace::Thread, m_structType->clone()))
+        , m_pointerToStructType(makeUniqueRef<AST::PointerType>(anonymousToken(Token::Type::Identifier), AST::AddressSpace::Thread, m_structType->clone()))
         , m_variableMapping(variableMapping)
     { }
 
@@ -115,7 +115,7 @@ public:
 
     UniqueRef<AST::AssignmentExpression> assignVariableIntoStruct(AST::VariableDeclaration& variable, AST::StructureElement* element)
     {
-        auto lhs = makeUniqueRef<AST::GlobalVariableReference>(variable.origin(), makeStructVariableReference(), element);
+        auto lhs = makeUniqueRef<AST::GlobalVariableReference>(variable.codeLocation(), makeStructVariableReference(), element);
         lhs->setType(variable.type()->clone());
         lhs->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
@@ -123,7 +123,7 @@ public:
         rhs->setType(variable.type()->clone());
         rhs->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
-        auto assignment = makeUniqueRef<AST::AssignmentExpression>(variable.origin(), WTFMove(lhs), WTFMove(rhs));
+        auto assignment = makeUniqueRef<AST::AssignmentExpression>(variable.codeLocation(), WTFMove(lhs), WTFMove(rhs));
         assignment->setType(variable.type()->clone());
         assignment->setTypeAnnotation(AST::RightValue());
 
@@ -134,7 +134,7 @@ public:
     {
         bool isEntryPoint = !!functionDefinition.entryPointType();
         if (isEntryPoint) {
-            auto structVariableDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.origin(), AST::Qualifiers(),
+            auto structVariableDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.codeLocation(), AST::Qualifiers(),
                 m_structType->clone(), String(), nullptr, nullptr);
 
             auto structVariableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(structVariableDeclaration));
@@ -143,24 +143,24 @@ public:
 
             AST::VariableDeclarations structVariableDeclarations;
             structVariableDeclarations.append(WTFMove(structVariableDeclaration));
-            auto structDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.origin(), WTFMove(structVariableDeclarations));
+            auto structDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.codeLocation(), WTFMove(structVariableDeclarations));
 
-            auto makePointerExpression = std::make_unique<AST::MakePointerExpression>(functionDefinition.origin(), WTFMove(structVariableReference));
+            auto makePointerExpression = std::make_unique<AST::MakePointerExpression>(functionDefinition.codeLocation(), WTFMove(structVariableReference));
             makePointerExpression->setType(m_pointerToStructType->clone());
             makePointerExpression->setTypeAnnotation(AST::RightValue());
 
-            auto pointerDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.origin(), AST::Qualifiers(),
+            auto pointerDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.codeLocation(), AST::Qualifiers(),
                 m_pointerToStructType->clone(), "wrapper"_s, nullptr, WTFMove(makePointerExpression));
             m_structVariable = &pointerDeclaration;
 
             AST::VariableDeclarations pointerVariableDeclarations;
             pointerVariableDeclarations.append(WTFMove(pointerDeclaration));
-            auto pointerDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.origin(), WTFMove(pointerVariableDeclarations));
+            auto pointerDeclarationStatement = makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.codeLocation(), WTFMove(pointerVariableDeclarations));
 
             functionDefinition.block().statements().insert(0, WTFMove(structDeclarationStatement));
             functionDefinition.block().statements().insert(1, WTFMove(pointerDeclarationStatement));
         } else {
-            auto pointerDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.origin(), AST::Qualifiers(),
+            auto pointerDeclaration = makeUniqueRef<AST::VariableDeclaration>(functionDefinition.codeLocation(), AST::Qualifiers(),
                 m_pointerToStructType->clone(), "wrapper"_s, nullptr, nullptr);
             m_structVariable = &pointerDeclaration;
             functionDefinition.parameters().append(WTFMove(pointerDeclaration));
@@ -203,7 +203,7 @@ public:
 
         auto type = variableReference.variable()->type()->clone();
         AST::TypeAnnotation typeAnnotation = variableReference.typeAnnotation();
-        auto* internalField = AST::replaceWith<AST::GlobalVariableReference>(variableReference, variableReference.origin(), makeStructVariableReference(), iter->value);
+        auto* internalField = AST::replaceWith<AST::GlobalVariableReference>(variableReference, variableReference.codeLocation(), makeStructVariableReference(), iter->value);
         internalField->setType(WTFMove(type));
         internalField->setTypeAnnotation(WTFMove(typeAnnotation));
     }
@@ -221,7 +221,7 @@ public:
             {
                 AST::VariableDeclarations declarations;
                 declarations.append(WTFMove(variableDeclaration));
-                statements.append(makeUniqueRef<AST::VariableDeclarationsStatement>(variable.origin(), WTFMove(declarations)));
+                statements.append(makeUniqueRef<AST::VariableDeclarationsStatement>(variable.codeLocation(), WTFMove(declarations)));
             }
 
             auto iter = m_variableMapping.find(&variable);
@@ -229,8 +229,7 @@ public:
                 statements.append(makeUniqueRef<AST::EffectfulExpressionStatement>(assignVariableIntoStruct(variable, iter->value)));
         }
 
-        auto origin = Lexer::Token(variableDeclarationsStatement.origin());
-        AST::replaceWith<AST::StatementList>(variableDeclarationsStatement, WTFMove(origin), WTFMove(statements));
+        AST::replaceWith<AST::StatementList>(variableDeclarationsStatement, variableDeclarationsStatement.codeLocation(), WTFMove(statements));
     }
 
 private:
@@ -256,13 +255,13 @@ void preserveVariableLifetimes(Program& program)
     for (auto& pair : escapedVariables) {
         auto* variable = pair.key;
         String name = pair.value;
-        elements.append(AST::StructureElement { Lexer::Token(variable->origin()), { }, variable->type()->clone(), WTFMove(name), nullptr });
+        elements.append(AST::StructureElement { variable->codeLocation(), { }, variable->type()->clone(), WTFMove(name), nullptr });
     }
 
     // Name of this doesn't matter, since we don't use struct names when
     // generating Metal type names. We just pick something here to make it
     // easy to read in AST dumps.
-    auto wrapperStructDefinition = makeUniqueRef<AST::StructureDefinition>(anonymousToken(Lexer::Token::Type::Struct), "__WrapperStruct__"_s, WTFMove(elements));
+    auto wrapperStructDefinition = makeUniqueRef<AST::StructureDefinition>(anonymousToken(Token::Type::Struct), "__WrapperStruct__"_s, WTFMove(elements));
 
     HashMap<AST::VariableDeclaration*, AST::StructureElement*> variableMapping;
     unsigned index = 0;
@@ -270,7 +269,7 @@ void preserveVariableLifetimes(Program& program)
         variableMapping.add(pair.key, &wrapperStructDefinition->structureElements()[index++]);
 
     {
-        auto wrapperStructType = AST::TypeReference::wrap(anonymousToken(Lexer::Token::Type::Identifier), wrapperStructDefinition);
+        auto wrapperStructType = AST::TypeReference::wrap(anonymousToken(Token::Type::Identifier), wrapperStructDefinition);
         PreserveLifetimes preserveLifetimes(wrapperStructType, variableMapping);
         preserveLifetimes.Visitor::visit(program);
     }
index 8abf0f6..cd603ae 100644 (file)
@@ -81,7 +81,7 @@ void PropertyResolver::visit(AST::FunctionDefinition& functionDefinition)
 {
     Visitor::visit(functionDefinition);
     if (!m_variableDeclarations.isEmpty())
-        functionDefinition.block().statements().insert(0, makeUniqueRef<AST::VariableDeclarationsStatement>(Lexer::Token(m_variableDeclarations[0]->origin()), WTFMove(m_variableDeclarations)));
+        functionDefinition.block().statements().insert(0, makeUniqueRef<AST::VariableDeclarationsStatement>(functionDefinition.codeLocation(), WTFMove(m_variableDeclarations)));
 }
 
 enum class WhichAnder {
@@ -98,24 +98,23 @@ struct AnderCallArgumentResult {
 template <typename ExpressionConstructor, typename TypeConstructor>
 static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Expression>& expression, UniqueRef<AST::UnnamedType> baseType, bool anderFunction, bool threadAnderFunction)
 {
+    auto location = expression->codeLocation();
     if (auto addressSpace = expression->typeAnnotation().leftAddressSpace()) {
         if (!anderFunction)
             return WTF::nullopt;
-        auto origin = expression->origin();
-        auto makeArrayReference = makeUniqueRef<ExpressionConstructor>(Lexer::Token(origin), WTFMove(expression));
-        makeArrayReference->setType(makeUniqueRef<TypeConstructor>(WTFMove(origin), *addressSpace, WTFMove(baseType)));
+        auto makeArrayReference = makeUniqueRef<ExpressionConstructor>(location, WTFMove(expression));
+        makeArrayReference->setType(makeUniqueRef<TypeConstructor>(location, *addressSpace, WTFMove(baseType)));
         makeArrayReference->setTypeAnnotation(AST::RightValue());
         return {{ WTFMove(makeArrayReference), WTF::nullopt, WhichAnder::Ander }};
     }
     if (threadAnderFunction) {
-        auto origin = expression->origin();
-        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(origin), AST::Qualifiers(), baseType->clone(), String(), nullptr, nullptr);
+        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), baseType->clone(), String(), nullptr, nullptr);
 
         auto variableReference1 = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(variableDeclaration));
         variableReference1->setType(baseType->clone());
         variableReference1->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
-        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(origin), WTFMove(variableReference1), WTFMove(expression));
+        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(variableReference1), WTFMove(expression));
         assignmentExpression->setType(baseType->clone());
         assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -123,15 +122,15 @@ static Optional<AnderCallArgumentResult> wrapAnderCallArgument(UniqueRef<AST::Ex
         variableReference2->setType(baseType->clone());
         variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
-        auto expression = makeUniqueRef<ExpressionConstructor>(Lexer::Token(origin), WTFMove(variableReference2));
-        auto resultType = makeUniqueRef<TypeConstructor>(Lexer::Token(origin), AST::AddressSpace::Thread, WTFMove(baseType));
+        auto expression = makeUniqueRef<ExpressionConstructor>(location, WTFMove(variableReference2));
+        auto resultType = makeUniqueRef<TypeConstructor>(location, AST::AddressSpace::Thread, WTFMove(baseType));
         expression->setType(resultType->clone());
         expression->setTypeAnnotation(AST::RightValue());
 
         Vector<UniqueRef<AST::Expression>> expressions;
         expressions.append(WTFMove(assignmentExpression));
         expressions.append(WTFMove(expression));
-        auto commaExpression = makeUniqueRef<AST::CommaExpression>(WTFMove(origin), WTFMove(expressions));
+        auto commaExpression = makeUniqueRef<AST::CommaExpression>(location, WTFMove(expressions));
         commaExpression->setType(WTFMove(resultType));
         commaExpression->setTypeAnnotation(AST::RightValue());
         return {{ WTFMove(commaExpression), { WTFMove(variableDeclaration) }, WhichAnder::ThreadAnder}};
@@ -167,6 +166,7 @@ static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpres
         arguments.append(WTFMove(variableReference));
     };
 
+    auto location = propertyAccessExpression.codeLocation();
     if (relevantAnder) {
         // *operator&.foo(&v) = newValue
         auto leftValue = leftValueFactory();
@@ -178,16 +178,16 @@ static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpres
         arguments.append(WTFMove(argument->expression));
         maybeAddIndexArgument(arguments);
 
-        auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(propertyAccessExpression.origin()), String(relevantAnder->name()), WTFMove(arguments));
+        auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(relevantAnder->name()), WTFMove(arguments));
         callExpression->setType(relevantAnder->type().clone());
         callExpression->setTypeAnnotation(AST::RightValue());
         callExpression->setFunction(*relevantAnder);
 
-        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(callExpression));
+        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(callExpression));
         dereferenceExpression->setType(downcast<AST::PointerType>(relevantAnder->type()).elementType().clone());
         dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
-        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(dereferenceExpression), WTFMove(newValue));
+        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(dereferenceExpression), WTFMove(newValue));
         assignmentExpression->setType(downcast<AST::PointerType>(relevantAnder->type()).elementType().clone());
         assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -202,12 +202,12 @@ static Optional<UniqueRef<AST::Expression>> setterCall(AST::PropertyAccessExpres
     maybeAddIndexArgument(arguments);
     arguments.append(WTFMove(newValue));
 
-    auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(propertyAccessExpression.origin()), String(propertyAccessExpression.setterFunction()->name()), WTFMove(arguments));
+    auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(propertyAccessExpression.setterFunction()->name()), WTFMove(arguments));
     callExpression->setType(propertyAccessExpression.setterFunction()->type().clone());
     callExpression->setTypeAnnotation(AST::RightValue());
     callExpression->setFunction(*propertyAccessExpression.setterFunction());
 
-    auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(propertyAccessExpression.origin()), leftValueFactory(), WTFMove(callExpression));
+    auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, leftValueFactory(), WTFMove(callExpression));
     assignmentExpression->setType(propertyAccessExpression.setterFunction()->type().clone());
     assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -226,6 +226,8 @@ static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpres
         arguments.append(WTFMove(variableReference));
     };
 
+    auto location = propertyAccessExpression.codeLocation();
+
     if (relevantAnder) {
         // *operator&.foo(&v)
         auto leftValue = leftValueFactory();
@@ -237,12 +239,12 @@ static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpres
         arguments.append(WTFMove(argument->expression));
         maybeAddIndexArgument(arguments);
 
-        auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(propertyAccessExpression.origin()), String(relevantAnder->name()), WTFMove(arguments));
+        auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(relevantAnder->name()), WTFMove(arguments));
         callExpression->setType(relevantAnder->type().clone());
         callExpression->setTypeAnnotation(AST::RightValue());
         callExpression->setFunction(*relevantAnder);
 
-        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(callExpression));
+        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(callExpression));
         dereferenceExpression->setType(downcast<AST::PointerType>(relevantAnder->type()).elementType().clone());
         dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread });
 
@@ -256,7 +258,7 @@ static Optional<UniqueRef<AST::Expression>> getterCall(AST::PropertyAccessExpres
     arguments.append(leftValueFactory());
     maybeAddIndexArgument(arguments);
 
-    auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(propertyAccessExpression.origin()), String(propertyAccessExpression.getterFunction()->name()), WTFMove(arguments));
+    auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(propertyAccessExpression.getterFunction()->name()), WTFMove(arguments));
     callExpression->setType(propertyAccessExpression.getterFunction()->type().clone());
     callExpression->setTypeAnnotation(AST::RightValue());
     callExpression->setFunction(*propertyAccessExpression.getterFunction());
@@ -313,14 +315,14 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
     AST::Expression& innerLeftExpression = leftExpression;
 
     // Create "p" variable.
-    auto pointerVariable = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(leftExpression->origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(makeUniqueRef<AST::PointerType>(Lexer::Token(leftExpression->origin()), *leftExpression->typeAnnotation().leftAddressSpace(), leftExpression->resolvedType().clone())), String(), nullptr, nullptr);
+    auto pointerVariable = makeUniqueRef<AST::VariableDeclaration>(leftExpression->codeLocation(), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(makeUniqueRef<AST::PointerType>(leftExpression->codeLocation(), *leftExpression->typeAnnotation().leftAddressSpace(), leftExpression->resolvedType().clone())), String(), nullptr, nullptr);
 
     // Create "q" and "r" variables.
     Vector<UniqueRef<AST::VariableDeclaration>> intermediateVariables;
     intermediateVariables.reserveInitialCapacity(chain.size() - 1);
     for (size_t i = 1; i < chain.size(); ++i) {
         auto& propertyAccessExpression = static_cast<AST::PropertyAccessExpression&>(chain[i]);
-        intermediateVariables.uncheckedAppend(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(propertyAccessExpression.origin()), AST::Qualifiers(), propertyAccessExpression.resolvedType().clone(), String(), nullptr, nullptr));
+        intermediateVariables.uncheckedAppend(makeUniqueRef<AST::VariableDeclaration>(propertyAccessExpression.codeLocation(), AST::Qualifiers(), propertyAccessExpression.resolvedType().clone(), String(), nullptr, nullptr));
     }
 
     // Consider a[foo()][b] = c;
@@ -351,15 +353,15 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
             continue;
         }
         auto& indexExpression = downcast<AST::IndexExpression>(propertyAccessExpression);
-        indexVariables.uncheckedAppend(makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(propertyAccessExpression.origin()), AST::Qualifiers(), indexExpression.indexExpression().resolvedType().clone(), String(), nullptr, nullptr));
+        indexVariables.uncheckedAppend(makeUniqueRef<AST::VariableDeclaration>(propertyAccessExpression.codeLocation(), AST::Qualifiers(), indexExpression.indexExpression().resolvedType().clone(), String(), nullptr, nullptr));
     }
 
     Vector<UniqueRef<AST::Expression>> expressions;
 
     // Step 1:
     {
-        auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(innerLeftExpression.origin()), WTFMove(leftExpression));
-        makePointerExpression->setType(makeUniqueRef<AST::PointerType>(Lexer::Token(innerLeftExpression.origin()), *innerLeftExpression.typeAnnotation().leftAddressSpace(), innerLeftExpression.resolvedType().clone()));
+        auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(innerLeftExpression.codeLocation(), WTFMove(leftExpression));
+        makePointerExpression->setType(makeUniqueRef<AST::PointerType>(innerLeftExpression.codeLocation(), *innerLeftExpression.typeAnnotation().leftAddressSpace(), innerLeftExpression.resolvedType().clone()));
         makePointerExpression->setTypeAnnotation(AST::RightValue());
 
         auto variableReference = makeUniqueRef<AST::VariableReference>(AST::VariableReference::wrap(pointerVariable));
@@ -367,7 +369,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
         variableReference->setType(pointerVariable->type()->clone());
         variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(innerLeftExpression.origin()), WTFMove(variableReference), WTFMove(makePointerExpression));
+        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(innerLeftExpression.codeLocation(), WTFMove(variableReference), WTFMove(makePointerExpression));
         assignmentExpression->setType(pointerVariable->type()->clone());
         assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -390,7 +392,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
         variableReference->setType(pointerVariable->type()->clone());
         variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference));
+        auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(propertyAccessExpression.codeLocation(), WTFMove(variableReference));
         ASSERT(pointerVariable->type());
         dereferenceExpression->setType(downcast<AST::PointerType>(*pointerVariable->type()).elementType().clone());
         dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(*pointerVariable->type()).addressSpace() });
@@ -407,7 +409,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
         variableReference->setType(indexVariable->get().type()->clone());
         variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference), indexExpression.takeIndex());
+        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(propertyAccessExpression.codeLocation(), WTFMove(variableReference), indexExpression.takeIndex());
         assignmentExpression->setType(indexVariable->get().type()->clone());
         assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -431,7 +433,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
         variableReference->setType(variableDeclaration.type()->clone());
         variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference), WTFMove(*callExpression));
+        auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(propertyAccessExpression.codeLocation(), WTFMove(variableReference), WTFMove(*callExpression));
         assignmentExpression->setType(variableDeclaration.type()->clone());
         assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -486,7 +488,7 @@ static Optional<ModifyResult> modify(AST::PropertyAccessExpression& propertyAcce
             variableReference->setType(pointerVariable->type()->clone());
             variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(propertyAccessExpression.origin()), WTFMove(variableReference));
+            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(propertyAccessExpression.codeLocation(), WTFMove(variableReference));
             ASSERT(pointerVariable->type());
             dereferenceExpression->setType(downcast<AST::PointerType>(*pointerVariable->type()).elementType().clone());
             dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(*pointerVariable->type()).addressSpace() });
@@ -534,8 +536,8 @@ void PropertyResolver::visit(AST::AssignmentExpression& assignmentExpression)
     }
     simplifyLeftValue(modifyResult->innerLeftValue);
 
-    Lexer::Token origin = assignmentExpression.origin();
-    auto* commaExpression = AST::replaceWith<AST::CommaExpression>(assignmentExpression, WTFMove(origin), WTFMove(modifyResult->expressions));
+    auto location = assignmentExpression.codeLocation();
+    auto* commaExpression = AST::replaceWith<AST::CommaExpression>(assignmentExpression, location, WTFMove(modifyResult->expressions));
     commaExpression->setType(WTFMove(type));
     commaExpression->setTypeAnnotation(AST::RightValue());
 
@@ -549,6 +551,9 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
     if (error())
         return;
 
+    auto location = readModifyWriteExpression.codeLocation();
+    auto leftValueLocation = readModifyWriteExpression.leftValue().codeLocation();
+
     if (readModifyWriteExpression.leftValue().typeAnnotation().leftAddressSpace()) {
         // Consider a++;
         // This would get transformed into:
@@ -561,15 +566,14 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
         simplifyLeftValue(readModifyWriteExpression.leftValue());
 
         auto baseType = readModifyWriteExpression.leftValue().resolvedType().clone();
-        auto pointerType = makeUniqueRef<AST::PointerType>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), *readModifyWriteExpression.leftValue().typeAnnotation().leftAddressSpace(), baseType->clone());
+        auto pointerType = makeUniqueRef<AST::PointerType>(leftValueLocation, *readModifyWriteExpression.leftValue().typeAnnotation().leftAddressSpace(), baseType->clone());
 
-        auto pointerVariable = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(pointerType->clone()), String(), nullptr, nullptr);
+        auto pointerVariable = makeUniqueRef<AST::VariableDeclaration>(leftValueLocation, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(pointerType->clone()), String(), nullptr, nullptr);
 
         Vector<UniqueRef<AST::Expression>> expressions;
 
         {
-            auto origin = Lexer::Token(readModifyWriteExpression.leftValue().origin());
-            auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(Lexer::Token(origin), readModifyWriteExpression.takeLeftValue());
+            auto makePointerExpression = makeUniqueRef<AST::MakePointerExpression>(leftValueLocation, readModifyWriteExpression.takeLeftValue());
             makePointerExpression->setType(pointerType->clone());
             makePointerExpression->setTypeAnnotation(AST::RightValue());
 
@@ -577,7 +581,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference->setType(pointerType->clone());
             variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(WTFMove(origin), WTFMove(variableReference), WTFMove(makePointerExpression));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(leftValueLocation, WTFMove(variableReference), WTFMove(makePointerExpression));
             assignmentExpression->setType(pointerType->clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -589,7 +593,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference1->setType(pointerType->clone());
             variableReference1->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference1));
+            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(variableReference1));
             dereferenceExpression->setType(baseType->clone());
             dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
@@ -597,7 +601,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference2->setType(baseType->clone());
             variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference2), WTFMove(dereferenceExpression));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(variableReference2), WTFMove(dereferenceExpression));
             assignmentExpression->setType(baseType->clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -610,7 +614,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
             auto newValueExpression = readModifyWriteExpression.takeNewValueExpression();
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference), WTFMove(newValueExpression));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(variableReference), WTFMove(newValueExpression));
             assignmentExpression->setType(baseType->clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -622,7 +626,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference1->setType(pointerType->clone());
             variableReference1->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(variableReference1));
+            auto dereferenceExpression = makeUniqueRef<AST::DereferenceExpression>(location, WTFMove(variableReference1));
             dereferenceExpression->setType(baseType->clone());
             dereferenceExpression->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
@@ -630,7 +634,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference2->setType(baseType->clone());
             variableReference2->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.origin()), WTFMove(dereferenceExpression), WTFMove(variableReference2));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(location, WTFMove(dereferenceExpression), WTFMove(variableReference2));
             assignmentExpression->setType(baseType->clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -644,8 +648,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
         UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue();
         UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue();
 
-        Lexer::Token origin = readModifyWriteExpression.origin();
-        auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(expressions));
+        auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, location, WTFMove(expressions));
         commaExpression->setType(WTFMove(type));
         commaExpression->setTypeAnnotation(AST::RightValue());
 
@@ -670,7 +673,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference->setType(readModifyWriteExpression.leftValue().resolvedType().clone());
             variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), WTFMove(variableReference), WTFMove(*lastGetterCallExpression));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(leftValueLocation, WTFMove(variableReference), WTFMove(*lastGetterCallExpression));
             assignmentExpression->setType(readModifyWriteExpression.leftValue().resolvedType().clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -683,7 +686,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
             variableReference->setTypeAnnotation(AST::LeftValue { AST::AddressSpace::Thread }); // FIXME: https://bugs.webkit.org/show_bug.cgi?id=198169 Is this right?
 
             auto newValueExpression = readModifyWriteExpression.takeNewValueExpression();
-            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(Lexer::Token(readModifyWriteExpression.leftValue().origin()), WTFMove(variableReference), WTFMove(newValueExpression));
+            auto assignmentExpression = makeUniqueRef<AST::AssignmentExpression>(leftValueLocation, WTFMove(variableReference), WTFMove(newValueExpression));
             assignmentExpression->setType(readModifyWriteExpression.leftValue().resolvedType().clone());
             assignmentExpression->setTypeAnnotation(AST::RightValue());
 
@@ -710,8 +713,7 @@ void PropertyResolver::visit(AST::ReadModifyWriteExpression& readModifyWriteExpr
     UniqueRef<AST::VariableDeclaration> oldVariableDeclaration = readModifyWriteExpression.takeOldValue();
     UniqueRef<AST::VariableDeclaration> newVariableDeclaration = readModifyWriteExpression.takeNewValue();
 
-    Lexer::Token origin = readModifyWriteExpression.origin();
-    auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, WTFMove(origin), WTFMove(modifyResult->expressions));
+    auto* commaExpression = AST::replaceWith<AST::CommaExpression>(readModifyWriteExpression, location, WTFMove(modifyResult->expressions));
     commaExpression->setType(WTFMove(type));
     commaExpression->setTypeAnnotation(AST::RightValue());
 
@@ -728,24 +730,23 @@ static Optional<AnderCallArgumentResult> anderCallArgument(AST::PropertyAccessEx
 
 void PropertyResolver::simplifyRightValue(AST::PropertyAccessExpression& propertyAccessExpression)
 {
-    Lexer::Token origin = propertyAccessExpression.origin();
+    auto location = propertyAccessExpression.codeLocation();
 
     checkErrorAndVisit(propertyAccessExpression.base());
 
     if (auto argument = anderCallArgument(propertyAccessExpression)) {
         auto* anderFunction = argument->whichAnder == WhichAnder::ThreadAnder ? propertyAccessExpression.threadAnderFunction() : propertyAccessExpression.anderFunction();
         ASSERT(anderFunction);
-        auto origin = propertyAccessExpression.origin();
         Vector<UniqueRef<AST::Expression>> arguments;
         arguments.append(WTFMove(argument->expression));
         if (is<AST::IndexExpression>(propertyAccessExpression))
             arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex());
-        auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(anderFunction->name()), WTFMove(arguments));
+        auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(anderFunction->name()), WTFMove(arguments));
         callExpression->setType(anderFunction->type().clone());
         callExpression->setTypeAnnotation(AST::RightValue());
         callExpression->setFunction(*anderFunction);
 
-        auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, WTFMove(origin), WTFMove(callExpression));
+        auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, location, WTFMove(callExpression));
         dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone());
         dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() });
 
@@ -763,11 +764,11 @@ void PropertyResolver::simplifyRightValue(AST::PropertyAccessExpression& propert
     if (is<AST::IndexExpression>(propertyAccessExpression)) {
         auto& indexExpression = downcast<AST::IndexExpression>(propertyAccessExpression);
         arguments.append(indexExpression.takeIndex());
-        callExpression = AST::replaceWith<AST::CallExpression>(indexExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments));
+        callExpression = AST::replaceWith<AST::CallExpression>(indexExpression, location, String(getterFunction.name()), WTFMove(arguments));
     } else {
         ASSERT(is<AST::DotExpression>(propertyAccessExpression));
         auto& dotExpression = downcast<AST::DotExpression>(propertyAccessExpression);
-        callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, WTFMove(origin), String(getterFunction.name()), WTFMove(arguments));
+        callExpression = AST::replaceWith<AST::CallExpression>(dotExpression, location, String(getterFunction.name()), WTFMove(arguments));
     }
     callExpression->setFunction(getterFunction);
     callExpression->setType(getterFunction.type().clone());
@@ -790,7 +791,7 @@ void LeftValueSimplifier::finishVisiting(AST::PropertyAccessExpression& property
 
     Visitor::visit(propertyAccessExpression.base());
 
-    Lexer::Token origin = propertyAccessExpression.origin();
+    auto location = propertyAccessExpression.codeLocation();
     auto* anderFunction = propertyAccessExpression.anderFunction();
 
     auto argument = anderCallArgument(propertyAccessExpression);
@@ -802,12 +803,12 @@ void LeftValueSimplifier::finishVisiting(AST::PropertyAccessExpression& property
     arguments.append(WTFMove(argument->expression));
     if (is<AST::IndexExpression>(propertyAccessExpression))
         arguments.append(downcast<AST::IndexExpression>(propertyAccessExpression).takeIndex());
-    auto callExpression = makeUniqueRef<AST::CallExpression>(Lexer::Token(origin), String(anderFunction->name()), WTFMove(arguments));
+    auto callExpression = makeUniqueRef<AST::CallExpression>(location, String(anderFunction->name()), WTFMove(arguments));
     callExpression->setType(anderFunction->type().clone());
     callExpression->setTypeAnnotation(AST::RightValue());
     callExpression->setFunction(*anderFunction);
 
-    auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, WTFMove(origin), WTFMove(callExpression));
+    auto* dereferenceExpression = AST::replaceWith<AST::DereferenceExpression>(propertyAccessExpression, location, WTFMove(callExpression));
     dereferenceExpression->setType(downcast<AST::PointerType>(anderFunction->type()).elementType().clone());
     dereferenceExpression->setTypeAnnotation(AST::LeftValue { downcast<AST::PointerType>(anderFunction->type()).addressSpace() });
 }
index efbe172..227c6a0 100644 (file)
@@ -65,10 +65,11 @@ bool synthesizeArrayOperatorLength(Program& program)
     bool isOperator = true;
 
     for (auto& arrayType : arrayTypes) {
-        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(arrayType.get().origin()), AST::Qualifiers(), arrayType.get().clone(), String(), nullptr, nullptr);
+        auto location = arrayType.get().codeLocation();
+        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), arrayType.get().clone(), String(), nullptr, nullptr);
         AST::VariableDeclarations parameters;
         parameters.append(WTFMove(variableDeclaration));
-        AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(arrayType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(arrayType.get().origin()), program.intrinsics().uintType()), "operator.length"_str, WTFMove(parameters), nullptr, isOperator));
+        AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().uintType()), "operator.length"_str, WTFMove(parameters), nullptr, isOperator));
         if (!program.append(WTFMove(nativeFunctionDeclaration)))
             return false;
     }
index 572c989..e0bfb67 100644 (file)
@@ -156,14 +156,15 @@ bool synthesizeConstructors(Program& program)
 
     for (auto& unnamedTypeKey : unnamedTypes) {
         auto& unnamedType = unnamedTypeKey.unnamedType();
+        auto location = unnamedType.codeLocation();
 
-        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(unnamedType.origin()), AST::Qualifiers(), unnamedType.clone(), String(), nullptr, nullptr);
+        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), unnamedType.clone(), String(), nullptr, nullptr);
         AST::VariableDeclarations parameters;
         parameters.append(WTFMove(variableDeclaration));
-        AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(Lexer::Token(unnamedType.origin()), AST::AttributeBlock(), WTF::nullopt, unnamedType.clone(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
+        AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType.clone(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
         program.append(WTFMove(copyConstructor));
 
-        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(Lexer::Token(unnamedType.origin()), AST::AttributeBlock(), WTF::nullopt, unnamedType.clone(), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
+        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, unnamedType.clone(), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
         if (!program.append(WTFMove(defaultConstructor)))
             return false;
     }
@@ -174,10 +175,12 @@ bool synthesizeConstructors(Program& program)
         if (is<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)) && downcast<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType)).isAtomic())
             continue;
 
-        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(namedType.get().origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get())), String(), nullptr, nullptr);
+        auto location = namedType.get().codeLocation();
+
+        auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, namedType.get())), String(), nullptr, nullptr);
         AST::VariableDeclarations parameters;
         parameters.append(WTFMove(variableDeclaration));
-        AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(Lexer::Token(namedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
+        AST::NativeFunctionDeclaration copyConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
         program.append(WTFMove(copyConstructor));
 
         if (is<AST::NativeTypeDeclaration>(static_cast<AST::NamedType&>(namedType))) {
@@ -185,7 +188,7 @@ bool synthesizeConstructors(Program& program)
             if (nativeTypeDeclaration.isOpaqueType())
                 continue;
         }
-        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(Lexer::Token(namedType.get().origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(namedType.get().origin()), namedType.get()), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
+        AST::NativeFunctionDeclaration defaultConstructor(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, namedType.get()), "operator cast"_str, AST::VariableDeclarations(), nullptr, isOperator));
         if (!program.append(WTFMove(defaultConstructor)))
             return false;
     }
index dd65291..c0ede86 100644 (file)
@@ -40,40 +40,41 @@ bool synthesizeEnumerationFunctions(Program& program)
 {
     bool isOperator = true;
     for (auto& enumerationDefinition : program.enumerationDefinitions()) {
+        auto location = enumerationDefinition->codeLocation();
         {
-            auto variableDeclaration1 = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), enumerationDefinition)), String(), nullptr, nullptr);
-            auto variableDeclaration2 = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), enumerationDefinition)), String(), nullptr, nullptr);
+            auto variableDeclaration1 = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, enumerationDefinition)), String(), nullptr, nullptr);
+            auto variableDeclaration2 = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, enumerationDefinition)), String(), nullptr, nullptr);
             AST::VariableDeclarations parameters;
             parameters.append(WTFMove(variableDeclaration1));
             parameters.append(WTFMove(variableDeclaration2));
-            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), program.intrinsics().boolType()), "operator=="_str, WTFMove(parameters), nullptr, isOperator));
+            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, AST::TypeReference::wrap(location, program.intrinsics().boolType()), "operator=="_str, WTFMove(parameters), nullptr, isOperator));
             if (!program.append(WTFMove(nativeFunctionDeclaration)))
                 return false;
         }
 
         {
-            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), enumerationDefinition)), String(), nullptr, nullptr);
+            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, enumerationDefinition)), String(), nullptr, nullptr);
             AST::VariableDeclarations parameters;
             parameters.append(WTFMove(variableDeclaration));
-            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type().clone(), "operator.value"_str, WTFMove(parameters), nullptr, isOperator));
+            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type().clone(), "operator.value"_str, WTFMove(parameters), nullptr, isOperator));
             if (!program.append(WTFMove(nativeFunctionDeclaration)))
                 return false;
         }
 
         {
-            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), enumerationDefinition)), String(), nullptr, nullptr);
+            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, enumerationDefinition)), String(), nullptr, nullptr);
             AST::VariableDeclarations parameters;
             parameters.append(WTFMove(variableDeclaration));
-            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type().clone(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
+            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, enumerationDefinition->type().clone(), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
             if (!program.append(WTFMove(nativeFunctionDeclaration)))
                 return false;
         }
 
         {
-            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(enumerationDefinition->origin()), AST::Qualifiers(), enumerationDefinition->type().clone(), String(), nullptr, nullptr);
+            auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(location, AST::Qualifiers(), enumerationDefinition->type().clone(), String(), nullptr, nullptr);
             AST::VariableDeclarations parameters;
             parameters.append(WTFMove(variableDeclaration));
-            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(enumerationDefinition->origin()), AST::AttributeBlock(), WTF::nullopt, UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(Lexer::Token(enumerationDefinition->origin()), enumerationDefinition)), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
+            AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(location, AST::AttributeBlock(), WTF::nullopt, UniqueRef<AST::UnnamedType>(AST::TypeReference::wrap(location, enumerationDefinition)), "operator cast"_str, WTFMove(parameters), nullptr, isOperator));
             if (!program.append(WTFMove(nativeFunctionDeclaration)))
                 return false;
         }
index 6d79809..543db19 100644 (file)
@@ -46,12 +46,12 @@ bool synthesizeStructureAccessors(Program& program)
         for (auto& structureElement : structureDefinition->structureElements()) {
             // The ander: operator&.field
             auto createAnder = [&](AST::AddressSpace addressSpace) -> AST::NativeFunctionDeclaration {
-                auto argumentType = makeUniqueRef<AST::PointerType>(Lexer::Token(structureElement.origin()), addressSpace, AST::TypeReference::wrap(Lexer::Token(structureElement.origin()), structureDefinition));
-                auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(Lexer::Token(structureElement.origin()), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), nullptr, nullptr);
+                auto argumentType = makeUniqueRef<AST::PointerType>(structureElement.codeLocation(), addressSpace, AST::TypeReference::wrap(structureElement.codeLocation(), structureDefinition));
+                auto variableDeclaration = makeUniqueRef<AST::VariableDeclaration>(structureElement.codeLocation(), AST::Qualifiers(), UniqueRef<AST::UnnamedType>(WTFMove(argumentType)), String(), nullptr, nullptr);
                 AST::VariableDeclarations parameters;
                 parameters.append(WTFMove(variableDeclaration));
-                auto returnType = makeUniqueRef<AST::PointerType>(Lexer::Token(structureElement.origin()), addressSpace, structureElement.type().clone());
-                AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(Lexer::Token(structureElement.origin()), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), makeString("operator&.", structureElement.name()), WTFMove(parameters), nullptr, isOperator));
+                auto returnType = makeUniqueRef<AST::PointerType>(structureElement.codeLocation(), addressSpace, structureElement.type().clone());
+                AST::NativeFunctionDeclaration nativeFunctionDeclaration(AST::FunctionDeclaration(structureElement.codeLocation(), AST::AttributeBlock(), WTF::nullopt, WTFMove(returnType), makeString("operator&.", structureElement.name()), WTFMove(parameters), nullptr, isOperator));
                 return nativeFunctionDeclaration;
             };
             if (!program.append(createAnder(AST::AddressSpace::Constant))