Changeset 160383 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Dec 10, 2013, 1:19:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r159790 r160383 246 246 m_statementDepth--; 247 247 ScopeRef scope = currentScope(); 248 SourceElements* sourceElements = parseSourceElements <CheckForStrictMode>(context);248 SourceElements* sourceElements = parseSourceElements(context, CheckForStrictMode); 249 249 if (!sourceElements || !consume(EOFTOK)) { 250 250 if (hasError()) … … 290 290 291 291 template <typename LexerType> 292 template < SourceElementsMode mode, class TreeBuilder> TreeSourceElements Parser<LexerType>::parseSourceElements(TreeBuilder& context)292 template <class TreeBuilder> TreeSourceElements Parser<LexerType>::parseSourceElements(TreeBuilder& context, SourceElementsMode mode) 293 293 { 294 294 const unsigned lengthOfUseStrictLiteral = 12; // "use strict".length … … 447 447 } else { 448 448 lastIdent = 0; 449 auto pattern = parseDeconstructionPattern <DeconstructToVariables>(context);449 auto pattern = parseDeconstructionPattern(context, DeconstructToVariables); 450 450 failIfFalse(pattern, "Cannot parse this deconstruction pattern"); 451 451 hasInitializer = match(EQUAL); … … 466 466 } while (match(COMMA)); 467 467 if (lastIdent) 468 lastPattern = createBindingPattern <DeconstructToVariables>(context, *lastIdent, 0);468 lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0); 469 469 return varDecls; 470 470 } 471 471 472 472 template <typename LexerType> 473 template < DeconstructionKind kind, class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, const Identifier& name, int depth)473 template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth) 474 474 { 475 475 ASSERT(!name.isEmpty()); … … 525 525 template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::tryParseDeconstructionPatternExpression(TreeBuilder& context) 526 526 { 527 return parseDeconstructionPattern <DeconstructToExpressions>(context);528 } 529 530 template <typename LexerType> 531 template < DeconstructionKind kind, class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::parseDeconstructionPattern(TreeBuilder& context, int depth)527 return parseDeconstructionPattern(context, DeconstructToExpressions); 528 } 529 530 template <typename LexerType> 531 template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::parseDeconstructionPattern(TreeBuilder& context, DeconstructionKind kind, int depth) 532 532 { 533 533 failIfStackOverflow(); … … 548 548 propagateError(); 549 549 JSTokenLocation location = m_token.m_location; 550 auto innerPattern = parseDeconstructionPattern <kind>(context, depth + 1);550 auto innerPattern = parseDeconstructionPattern(context, kind, depth + 1); 551 551 if (kind == DeconstructToExpressions && !innerPattern) 552 552 return 0; … … 579 579 next(); 580 580 if (consume(COLON)) 581 innerPattern = parseDeconstructionPattern <kind>(context, depth + 1);581 innerPattern = parseDeconstructionPattern(context, kind, depth + 1); 582 582 else 583 innerPattern = createBindingPattern <kind>(context, propertyName, depth);583 innerPattern = createBindingPattern(context, kind, propertyName, depth); 584 584 } else { 585 585 JSTokenType tokenType = m_token.m_type; … … 611 611 failWithMessage("Expected a ':' prior to named property deconstruction"); 612 612 } 613 innerPattern = parseDeconstructionPattern <kind>(context, depth + 1);613 innerPattern = parseDeconstructionPattern(context, kind, depth + 1); 614 614 } 615 615 if (kind == DeconstructToExpressions && !innerPattern) … … 632 632 failWithMessage("Expected a parameter pattern or a ')' in parameter list"); 633 633 } 634 pattern = createBindingPattern <kind>(context, *m_token.m_data.ident, depth);634 pattern = createBindingPattern(context, kind, *m_token.m_data.ident, depth); 635 635 next(); 636 636 break; … … 962 962 failIfFalse(condition, "Cannot parse switch clause"); 963 963 consumeOrFail(COLON, "Expected a ':' after switch clause expression"); 964 TreeSourceElements statements = parseSourceElements <DontCheckForStrictMode>(context);964 TreeSourceElements statements = parseSourceElements(context, DontCheckForStrictMode); 965 965 failIfFalse(statements, "Cannot parse the body of a switch clause"); 966 966 TreeClause clause = context.createClause(condition, statements); … … 973 973 failIfFalse(condition, "Cannot parse switch case expression"); 974 974 consumeOrFail(COLON, "Expected a ':' after switch clause expression"); 975 TreeSourceElements statements = parseSourceElements <DontCheckForStrictMode>(context);975 TreeSourceElements statements = parseSourceElements(context, DontCheckForStrictMode); 976 976 failIfFalse(statements, "Cannot parse the body of a switch clause"); 977 977 clause = context.createClause(condition, statements); … … 988 988 next(); 989 989 consumeOrFail(COLON, "Expected a ':' after switch default clause"); 990 TreeSourceElements statements = parseSourceElements <DontCheckForStrictMode>(context);990 TreeSourceElements statements = parseSourceElements(context, DontCheckForStrictMode); 991 991 failIfFalse(statements, "Cannot parse the body of a switch default clause"); 992 992 return context.createClause(0, statements); … … 1066 1066 return context.createBlockStatement(location, 0, start, m_lastTokenEndPosition.line); 1067 1067 } 1068 TreeSourceElements subtree = parseSourceElements <DontCheckForStrictMode>(context);1068 TreeSourceElements subtree = parseSourceElements(context, DontCheckForStrictMode); 1069 1069 failIfFalse(subtree, "Cannot parse the body of the block statement"); 1070 1070 matchOrFail(CLOSEBRACE, "Expected a closing '}' at the end of a block statement"); … … 1144 1144 template <class TreeBuilder> TreeFormalParameterList Parser<LexerType>::parseFormalParameters(TreeBuilder& context) 1145 1145 { 1146 auto parameter = parseDeconstructionPattern <DeconstructToParameters>(context);1146 auto parameter = parseDeconstructionPattern(context, DeconstructToParameters); 1147 1147 failIfFalse(parameter, "Cannot parse parameter pattern"); 1148 1148 TreeFormalParameterList list = context.createFormalParameterList(parameter); 1149 1149 TreeFormalParameterList tail = list; 1150 1150 while (consume(COMMA)) { 1151 parameter = parseDeconstructionPattern <DeconstructToParameters>(context);1151 parameter = parseDeconstructionPattern(context, DeconstructToParameters); 1152 1152 failIfFalse(parameter, "Cannot parse parameter pattern"); 1153 1153 tail = context.createFormalParameterList(tail, parameter); … … 1170 1170 m_statementDepth = 0; 1171 1171 typename TreeBuilder::FunctionBodyBuilder bodyBuilder(const_cast<VM*>(m_vm), m_lexer.get()); 1172 failIfFalse(parseSourceElements <CheckForStrictMode>(bodyBuilder), "Cannot parse body of this function");1172 failIfFalse(parseSourceElements(bodyBuilder, CheckForStrictMode), "Cannot parse body of this function"); 1173 1173 unsigned endColumn = tokenColumn(); 1174 1174 return context.createFunctionBody(startLocation, tokenLocation(), startColumn, endColumn, strictMode()); … … 1190 1190 1191 1191 template <typename LexerType> 1192 template < FunctionRequirements requirements, FunctionParseMode mode, bool nameIsInContainingScope, class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, unsigned& openBraceOffset, unsigned& closeBraceOffset, int& bodyStartLine, unsigned& bodyStartColumn)1192 template <class TreeBuilder> bool Parser<LexerType>::parseFunctionInfo(TreeBuilder& context, FunctionRequirements requirements, FunctionParseMode mode, bool nameIsInContainingScope, const Identifier*& name, TreeFormalParameterList& parameters, TreeFunctionBody& body, unsigned& openBraceOffset, unsigned& closeBraceOffset, int& bodyStartLine, unsigned& bodyStartColumn) 1193 1193 { 1194 1194 AutoPopScopeRef functionScope(this, pushScope()); … … 1312 1312 int bodyStartLine = 0; 1313 1313 unsigned bodyStartColumn = 0; 1314 failIfFalse((parseFunctionInfo <FunctionNeedsName, FunctionMode, true>(context, name, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse this function");1314 failIfFalse((parseFunctionInfo(context, FunctionNeedsName, FunctionMode, true, name, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse this function"); 1315 1315 failIfFalse(name, "Function statements must have a name"); 1316 1316 failIfFalseIfStrict(declareVariable(name), "Cannot declare a function named '", name->impl(), "' in strict mode"); … … 1674 1674 1675 1675 template <typename LexerType> 1676 template < bool complete, class TreeBuilder> TreeProperty Parser<LexerType>::parseProperty(TreeBuilder& context)1676 template <class TreeBuilder> TreeProperty Parser<LexerType>::parseProperty(TreeBuilder& context, bool complete) 1677 1677 { 1678 1678 bool wasIdent = false; … … 1692 1692 TreeExpression node = parseAssignmentExpression(context); 1693 1693 failIfFalse(node, "Cannot parse expression for property declaration"); 1694 return context. template createProperty<complete>(ident, node, PropertyNode::Constant);1694 return context.createProperty(ident, node, PropertyNode::Constant, complete); 1695 1695 } 1696 1696 failIfFalse(wasIdent, "Expected an identifier as property name"); … … 1721 1721 if (type == PropertyNode::Getter) { 1722 1722 failIfFalse(match(OPENPAREN), "Expected a parameter list for getter definition"); 1723 failIfFalse((parseFunctionInfo <FunctionNoRequirements, GetterMode, false>(context, accessorName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse getter definition");1723 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, GetterMode, false, accessorName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse getter definition"); 1724 1724 } else { 1725 1725 failIfFalse(match(OPENPAREN), "Expected a parameter list for setter definition"); 1726 failIfFalse((parseFunctionInfo <FunctionNoRequirements, SetterMode, false>(context, accessorName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse setter definition");1726 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, SetterMode, false, accessorName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse setter definition"); 1727 1727 } 1728 1728 if (stringPropertyName) 1729 return context. template createGetterOrSetterProperty<complete>(location, type, stringPropertyName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, m_lastTokenEndPosition.line, bodyStartColumn);1730 return context. template createGetterOrSetterProperty<complete>(const_cast<VM*>(m_vm), location, type, numericPropertyName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, m_lastTokenEndPosition.line, bodyStartColumn);1729 return context.createGetterOrSetterProperty(location, type, complete, stringPropertyName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, m_lastTokenEndPosition.line, bodyStartColumn); 1730 return context.createGetterOrSetterProperty(const_cast<VM*>(m_vm), location, type, complete, numericPropertyName, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, m_lastTokenEndPosition.line, bodyStartColumn); 1731 1731 } 1732 1732 case NUMBER: { … … 1736 1736 TreeExpression node = parseAssignmentExpression(context); 1737 1737 failIfFalse(node, "Cannot parse expression for property declaration"); 1738 return context. template createProperty<complete>(const_cast<VM*>(m_vm), propertyName, node, PropertyNode::Constant);1738 return context.createProperty(const_cast<VM*>(m_vm), propertyName, node, PropertyNode::Constant, complete); 1739 1739 } 1740 1740 case OPENBRACKET: { … … 1747 1747 TreeExpression node = parseAssignmentExpression(context); 1748 1748 failIfFalse(node, "Cannot parse expression for property declaration"); 1749 return context. template createProperty<complete>(const_cast<VM*>(m_vm), propertyName, node, PropertyNode::Constant);1749 return context.createProperty(const_cast<VM*>(m_vm), propertyName, node, PropertyNode::Constant, complete); 1750 1750 } 1751 1751 default: … … 1769 1769 } 1770 1770 1771 TreeProperty property = parseProperty <false>(context);1771 TreeProperty property = parseProperty(context, false); 1772 1772 failIfFalse(property, "Cannot parse object literal property"); 1773 1773 if (!m_syntaxAlreadyValidated && context.getType(property) != PropertyNode::Constant) { … … 1783 1783 break; 1784 1784 JSTokenLocation propertyLocation(tokenLocation()); 1785 property = parseProperty <false>(context);1785 property = parseProperty(context, false); 1786 1786 failIfFalse(property, "Cannot parse object literal property"); 1787 1787 if (!m_syntaxAlreadyValidated && context.getType(property) != PropertyNode::Constant) { … … 1813 1813 } 1814 1814 1815 TreeProperty property = parseProperty <true>(context);1815 TreeProperty property = parseProperty(context, true); 1816 1816 failIfFalse(property, "Cannot parse object literal property"); 1817 1817 … … 1830 1830 break; 1831 1831 JSTokenLocation propertyLocation(tokenLocation()); 1832 property = parseProperty <true>(context);1832 property = parseProperty(context, true); 1833 1833 failIfFalse(property, "Cannot parse object literal property"); 1834 1834 if (!m_syntaxAlreadyValidated && context.getName(property)) { … … 2077 2077 location = tokenLocation(); 2078 2078 next(); 2079 failIfFalse((parseFunctionInfo <FunctionNoRequirements, FunctionMode, false>(context, name, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse function expression");2079 failIfFalse((parseFunctionInfo(context, FunctionNoRequirements, FunctionMode, false, name, parameters, body, openBraceOffset, closeBraceOffset, bodyStartLine, bodyStartColumn)), "Cannot parse function expression"); 2080 2080 base = context.createFunctionExpr(location, name, body, parameters, openBraceOffset, closeBraceOffset, bodyStartLine, m_lastTokenEndPosition.line, bodyStartColumn); 2081 2081 } else
Note:
See TracChangeset
for help on using the changeset viewer.