Changeset 186246 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Jul 2, 2015, 4:53:10 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r186047 r186246 412 412 int end = 0; 413 413 int scratch; 414 TreeDe constructionPattern scratch1 = 0;414 TreeDestructuringPattern scratch1 = 0; 415 415 TreeExpression scratch2 = 0; 416 416 JSTextPosition scratch3; … … 484 484 485 485 template <typename LexerType> 486 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, TreeDe constructionPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd, VarDeclarationListContext declarationListContext)486 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseVarDeclarationList(TreeBuilder& context, int& declarations, TreeDestructuringPattern& lastPattern, TreeExpression& lastInitializer, JSTextPosition& identStart, JSTextPosition& initStart, JSTextPosition& initEnd, VarDeclarationListContext declarationListContext) 487 487 { 488 488 TreeExpression head = 0; … … 523 523 } else { 524 524 lastIdent = 0; 525 auto pattern = parseDe constructionPattern(context, DeconstructToVariables);526 failIfFalse(pattern, "Cannot parse this de constructionpattern");525 auto pattern = parseDestructuringPattern(context, DestructureToVariables); 526 failIfFalse(pattern, "Cannot parse this destructuring pattern"); 527 527 hasInitializer = match(EQUAL); 528 528 failIfTrue(declarationListContext == VarDeclarationContext && !hasInitializer, "Expected an initializer in destructuring variable declaration"); … … 531 531 next(TreeBuilder::DontBuildStrings); // consume '=' 532 532 TreeExpression rhs = parseAssignmentExpression(context); 533 node = context.createDe constructingAssignment(location, pattern, rhs);533 node = context.createDestructuringAssignment(location, pattern, rhs); 534 534 lastInitializer = rhs; 535 535 } … … 545 545 } while (match(COMMA)); 546 546 if (lastIdent) 547 lastPattern = createBindingPattern(context, De constructToVariables, *lastIdent, 0, lastIdentToken);547 lastPattern = createBindingPattern(context, DestructureToVariables, *lastIdent, 0, lastIdentToken); 548 548 return head; 549 549 } 550 550 551 551 template <typename LexerType> 552 template <class TreeBuilder> TreeDe constructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth, JSToken token)552 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DestructuringKind kind, const Identifier& name, int depth, JSToken token) 553 553 { 554 554 ASSERT(!name.isNull()); … … 556 556 ASSERT(name.impl()->isAtomic() || name.impl()->isSymbol()); 557 557 if (depth) { 558 if (kind == De constructToVariables)559 failIfFalseIfStrict(declareVariable(&name), "Cannot de constructto a variable named '", name.impl(), "' in strict mode");560 if (kind == De constructToParameters) {558 if (kind == DestructureToVariables) 559 failIfFalseIfStrict(declareVariable(&name), "Cannot destructure to a variable named '", name.impl(), "' in strict mode"); 560 if (kind == DestructureToParameters) { 561 561 auto bindingResult = declareBoundParameter(&name); 562 562 if (bindingResult == Scope::StrictBindingFailed && strictMode()) { 563 semanticFailIfTrue(m_vm->propertyNames->arguments == name || m_vm->propertyNames->eval == name, "Cannot de constructto a parameter name '", name.impl(), "' in strict mode");563 semanticFailIfTrue(m_vm->propertyNames->arguments == name || m_vm->propertyNames->eval == name, "Cannot destructure to a parameter name '", name.impl(), "' in strict mode"); 564 564 if (m_lastFunctionName && name == *m_lastFunctionName) 565 semanticFail("Cannot de constructto '", name.impl(), "' as it shadows the name of a strict mode function");565 semanticFail("Cannot destructure to '", name.impl(), "' as it shadows the name of a strict mode function"); 566 566 semanticFailureDueToKeyword("bound parameter name"); 567 567 if (hasDeclaredParameter(name)) 568 semanticFail("Cannot de constructto '", name.impl(), "' as it has already been declared");568 semanticFail("Cannot destructure to '", name.impl(), "' as it has already been declared"); 569 569 semanticFail("Cannot bind to a parameter named '", name.impl(), "' in strict mode"); 570 570 } … … 572 572 semanticFailureDueToKeyword("bound parameter name"); 573 573 if (hasDeclaredParameter(name)) 574 semanticFail("Cannot de constructto '", name.impl(), "' as it has already been declared");575 semanticFail("Cannot de constructto a parameter named '", name.impl(), "'");574 semanticFail("Cannot destructure to '", name.impl(), "' as it has already been declared"); 575 semanticFail("Cannot destructure to a parameter named '", name.impl(), "'"); 576 576 } 577 577 } 578 if (kind != De constructToExpressions)578 if (kind != DestructureToExpressions) 579 579 context.addVar(&name, DeclarationStacks::HasInitializer); 580 580 581 581 } else { 582 if (kind == De constructToVariables) {582 if (kind == DestructureToVariables) { 583 583 failIfFalseIfStrict(declareVariable(&name), "Cannot declare a variable named '", name.impl(), "' in strict mode"); 584 584 context.addVar(&name, DeclarationStacks::HasInitializer); 585 585 } 586 586 587 if (kind == De constructToParameters) {587 if (kind == DestructureToParameters) { 588 588 bool declarationResult = declareParameter(&name); 589 589 if (!declarationResult && strictMode()) { 590 semanticFailIfTrue(m_vm->propertyNames->arguments == name || m_vm->propertyNames->eval == name, "Cannot de constructto a parameter name '", name.impl(), "' in strict mode");590 semanticFailIfTrue(m_vm->propertyNames->arguments == name || m_vm->propertyNames->eval == name, "Cannot destructure to a parameter name '", name.impl(), "' in strict mode"); 591 591 if (m_lastFunctionName && name == *m_lastFunctionName) 592 592 semanticFail("Cannot declare a parameter named '", name.impl(), "' as it shadows the name of a strict mode function"); … … 638 638 639 639 template <typename LexerType> 640 template <class TreeBuilder> TreeDe constructionPattern Parser<LexerType>::tryParseDeconstructionPatternExpression(TreeBuilder& context)641 { 642 return parseDe constructionPattern(context, DeconstructToExpressions);643 } 644 645 template <typename LexerType> 646 template <class TreeBuilder> TreeDe constructionPattern Parser<LexerType>::parseDeconstructionPattern(TreeBuilder& context, DeconstructionKind kind, int depth)640 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::tryParseDestructuringPatternExpression(TreeBuilder& context) 641 { 642 return parseDestructuringPattern(context, DestructureToExpressions); 643 } 644 645 template <typename LexerType> 646 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseDestructuringPattern(TreeBuilder& context, DestructuringKind kind, int depth) 647 647 { 648 648 failIfStackOverflow(); 649 649 int nonLHSCount = m_nonLHSCount; 650 TreeDe constructionPattern pattern;650 TreeDestructuringPattern pattern; 651 651 switch (m_token.m_type) { 652 652 case OPENBRACKET: { … … 670 670 JSTokenLocation location = m_token.m_location; 671 671 next(); 672 auto innerPattern = parseDe constructionPattern(context, kind, depth + 1);673 if (kind == De constructToExpressions && !innerPattern)672 auto innerPattern = parseDestructuringPattern(context, kind, depth + 1); 673 if (kind == DestructureToExpressions && !innerPattern) 674 674 return 0; 675 failIfFalse(innerPattern, "Cannot parse this de constructionpattern");676 677 failIfTrue(kind != De constructToExpressions && !context.isBindingNode(innerPattern), "Expected identifier for a rest element deconstructionpattern");675 failIfFalse(innerPattern, "Cannot parse this destructuring pattern"); 676 677 failIfTrue(kind != DestructureToExpressions && !context.isBindingNode(innerPattern), "Expected identifier for a rest element destructuring pattern"); 678 678 679 679 context.appendArrayPatternRestEntry(arrayPattern, location, innerPattern); … … 683 683 684 684 JSTokenLocation location = m_token.m_location; 685 auto innerPattern = parseDe constructionPattern(context, kind, depth + 1);686 if (kind == De constructToExpressions && !innerPattern)685 auto innerPattern = parseDestructuringPattern(context, kind, depth + 1); 686 if (kind == DestructureToExpressions && !innerPattern) 687 687 return 0; 688 failIfFalse(innerPattern, "Cannot parse this de constructionpattern");689 TreeExpression defaultValue = parseDefaultValueForDe constructionPattern(context);690 failIfTrue(kind == De constructToParameters && defaultValue, "Default values in destructuring parameters are currently not supported");688 failIfFalse(innerPattern, "Cannot parse this destructuring pattern"); 689 TreeExpression defaultValue = parseDefaultValueForDestructuringPattern(context); 690 failIfTrue(kind == DestructureToParameters && defaultValue, "Default values in destructuring parameters are currently not supported"); 691 691 context.appendArrayPatternEntry(arrayPattern, location, innerPattern, defaultValue); 692 692 } while (consume(COMMA)); 693 693 694 if (kind == De constructToExpressions && !match(CLOSEBRACKET))694 if (kind == DestructureToExpressions && !match(CLOSEBRACKET)) 695 695 return 0; 696 consumeOrFail(CLOSEBRACKET, restElementWasFound ? "Expected a closing ']' following a rest element de construction pattern" : "Expected either a closing ']' or a ',' following an element deconstructionpattern");696 consumeOrFail(CLOSEBRACKET, restElementWasFound ? "Expected a closing ']' following a rest element destructuring pattern" : "Expected either a closing ']' or a ',' following an element destructuring pattern"); 697 697 context.finishArrayPattern(arrayPattern, divotStart, divotStart, lastTokenEndPosition()); 698 698 pattern = arrayPattern; … … 710 710 711 711 Identifier propertyName; 712 TreeDe constructionPattern innerPattern = 0;712 TreeDestructuringPattern innerPattern = 0; 713 713 JSTokenLocation location = m_token.m_location; 714 714 if (match(IDENT)) { … … 717 717 next(); 718 718 if (consume(COLON)) 719 innerPattern = parseDe constructionPattern(context, kind, depth + 1);719 innerPattern = parseDestructuringPattern(context, kind, depth + 1); 720 720 else 721 721 innerPattern = createBindingPattern(context, kind, propertyName, depth, identifierToken); … … 733 733 default: 734 734 if (m_token.m_type != RESERVED && m_token.m_type != RESERVED_IF_STRICT && !(m_token.m_type & KeywordTokenFlag)) { 735 if (kind == De constructToExpressions)735 if (kind == DestructureToExpressions) 736 736 return 0; 737 737 failWithMessage("Expected a property name"); … … 742 742 next(); 743 743 if (!consume(COLON)) { 744 if (kind == De constructToExpressions)744 if (kind == DestructureToExpressions) 745 745 return 0; 746 semanticFailIfTrue(tokenType == RESERVED, "Cannot use abbreviated de constructionsyntax for reserved name '", propertyName.impl(), "'");747 semanticFailIfTrue(tokenType == RESERVED_IF_STRICT, "Cannot use abbreviated de constructionsyntax for reserved name '", propertyName.impl(), "' in strict mode");748 semanticFailIfTrue(tokenType & KeywordTokenFlag, "Cannot use abbreviated de constructionsyntax for keyword '", propertyName.impl(), "'");746 semanticFailIfTrue(tokenType == RESERVED, "Cannot use abbreviated destructuring syntax for reserved name '", propertyName.impl(), "'"); 747 semanticFailIfTrue(tokenType == RESERVED_IF_STRICT, "Cannot use abbreviated destructuring syntax for reserved name '", propertyName.impl(), "' in strict mode"); 748 semanticFailIfTrue(tokenType & KeywordTokenFlag, "Cannot use abbreviated destructuring syntax for keyword '", propertyName.impl(), "'"); 749 749 750 failWithMessage("Expected a ':' prior to named property deconstruction");750 failWithMessage("Expected a ':' prior to a named destructuring property"); 751 751 } 752 innerPattern = parseDe constructionPattern(context, kind, depth + 1);752 innerPattern = parseDestructuringPattern(context, kind, depth + 1); 753 753 } 754 if (kind == De constructToExpressions && !innerPattern)754 if (kind == DestructureToExpressions && !innerPattern) 755 755 return 0; 756 failIfFalse(innerPattern, "Cannot parse this de constructionpattern");757 TreeExpression defaultValue = parseDefaultValueForDe constructionPattern(context);758 failIfTrue(kind == De constructToParameters && defaultValue, "Default values in destructuring parameters are currently not supported");756 failIfFalse(innerPattern, "Cannot parse this destructuring pattern"); 757 TreeExpression defaultValue = parseDefaultValueForDestructuringPattern(context); 758 failIfTrue(kind == DestructureToParameters && defaultValue, "Default values in destructuring parameters are currently not supported"); 759 759 context.appendObjectPatternEntry(objectPattern, location, wasString, propertyName, innerPattern, defaultValue); 760 760 } while (consume(COMMA)); 761 761 762 if (kind == De constructToExpressions && !match(CLOSEBRACE))762 if (kind == DestructureToExpressions && !match(CLOSEBRACE)) 763 763 return 0; 764 consumeOrFail(CLOSEBRACE, "Expected either a closing '}' or an ',' after a property de constructionpattern");764 consumeOrFail(CLOSEBRACE, "Expected either a closing '}' or an ',' after a property destructuring pattern"); 765 765 pattern = objectPattern; 766 766 break; … … 769 769 default: { 770 770 if (!match(IDENT)) { 771 if (kind == De constructToExpressions)771 if (kind == DestructureToExpressions) 772 772 return 0; 773 773 semanticFailureDueToKeyword("variable name"); … … 784 784 785 785 template <typename LexerType> 786 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseDefaultValueForDe constructionPattern(TreeBuilder& context)786 template <class TreeBuilder> TreeExpression Parser<LexerType>::parseDefaultValueForDestructuringPattern(TreeBuilder& context) 787 787 { 788 788 if (!match(EQUAL)) … … 835 835 JSTextPosition declsEnd; 836 836 TreeExpression decls = 0; 837 TreeDe constructionPattern pattern = 0;837 TreeDestructuringPattern pattern = 0; 838 838 if (match(VAR)) { 839 839 /* … … 841 841 for (var varDeclarationList; expressionOpt; expressionOpt) 842 842 */ 843 TreeDe constructionPattern forInTarget = 0;843 TreeDestructuringPattern forInTarget = 0; 844 844 TreeExpression forInInitializer = 0; 845 845 m_allowsIn = false; … … 891 891 SavePoint savePoint = createSavePoint(); 892 892 declsStart = tokenStartPosition(); 893 pattern = tryParseDe constructionPatternExpression(context);893 pattern = tryParseDestructuringPatternExpression(context); 894 894 declsEnd = lastTokenEndPosition(); 895 895 if (pattern && (match(INTOKEN) || (match(IDENT) && *m_token.m_data.ident == m_vm->propertyNames->of))) … … 1350 1350 template <class TreeBuilder> TreeFormalParameterList Parser<LexerType>::parseFormalParameters(TreeBuilder& context) 1351 1351 { 1352 auto parameter = parseDe constructionPattern(context, DeconstructToParameters);1352 auto parameter = parseDestructuringPattern(context, DestructureToParameters); 1353 1353 failIfFalse(parameter, "Cannot parse parameter pattern"); 1354 1354 TreeFormalParameterList list = context.createFormalParameterList(parameter); 1355 1355 TreeFormalParameterList tail = list; 1356 1356 while (consume(COMMA)) { 1357 parameter = parseDe constructionPattern(context, DeconstructToParameters);1357 parameter = parseDestructuringPattern(context, DestructureToParameters); 1358 1358 failIfFalse(parameter, "Cannot parse parameter pattern"); 1359 1359 tail = context.createFormalParameterList(tail, parameter); … … 1430 1430 consumeOrFail(CLOSEPAREN, "Expected a ')' or a ',' after a parameter declaration"); 1431 1431 } else { 1432 auto parameter = parseDe constructionPattern(context, DeconstructToParameters);1432 auto parameter = parseDestructuringPattern(context, DestructureToParameters); 1433 1433 failIfFalse(parameter, "Cannot parse parameter pattern"); 1434 1434 info.parameters = context.createFormalParameterList(parameter); … … 1450 1450 else if (mode == SetterMode) { 1451 1451 failIfTrue(match(CLOSEPAREN), "setter functions must have one parameter"); 1452 auto parameter = parseDe constructionPattern(context, DeconstructToParameters);1452 auto parameter = parseDestructuringPattern(context, DestructureToParameters); 1453 1453 failIfFalse(parameter, "setter functions must have one parameter"); 1454 1454 info.parameters = context.createFormalParameterList(parameter); … … 2075 2075 if (match(OPENBRACE) || match(OPENBRACKET)) { 2076 2076 SavePoint savePoint = createSavePoint(); 2077 auto pattern = tryParseDe constructionPatternExpression(context);2077 auto pattern = tryParseDestructuringPatternExpression(context); 2078 2078 if (pattern && consume(EQUAL)) { 2079 2079 auto rhs = parseAssignmentExpression(context); 2080 2080 if (rhs) 2081 return context.createDe constructingAssignment(location, pattern, rhs);2081 return context.createDestructuringAssignment(location, pattern, rhs); 2082 2082 } 2083 2083 restoreSavePoint(savePoint);
Note:
See TracChangeset
for help on using the changeset viewer.