Changeset 43642 in webkit for trunk/JavaScriptCore/parser
- Timestamp:
- May 13, 2009, 11:14:48 AM (16 years ago)
- Location:
- trunk/JavaScriptCore/parser
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Grammar.y
r43479 r43642 26 26 #include "config.h" 27 27 28 #include <string.h> 29 #include <stdlib.h> 28 #include "CommonIdentifiers.h" 29 #include "JSGlobalData.h" 30 #include "JSObject.h" 31 #include "JSString.h" 30 32 #include "JSValue.h" 31 #include " JSObject.h"33 #include "Lexer.h" 32 34 #include "NodeConstructors.h" 33 #include "Lexer.h"34 #include "JSString.h"35 #include "JSGlobalData.h"36 #include "CommonIdentifiers.h"37 35 #include "NodeInfo.h" 38 36 #include "Parser.h" 37 #include <stdlib.h> 38 #include <string.h> 39 39 #include <wtf/MathExtras.h> 40 40 … … 52 52 int jscyylex(void* lvalp, void* llocp, void* globalPtr); 53 53 int jscyyerror(const char*); 54 54 55 static inline bool allowAutomaticSemicolon(JSC::Lexer&, int); 55 56 … … 58 59 59 60 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon(*LEXER, yychar)) YYABORT; } while (0) 60 #define SET_EXCEPTION_LOCATION(node, start, divot, end) node->setExceptionSourceCode((divot), (divot) - (start), (end) - (divot))61 61 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line) 62 62 … … 64 64 using namespace std; 65 65 66 static ExpressionNode* makeAssignNode(void*, ExpressionNode* loc, Operator, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end); 67 static ExpressionNode* makePrefixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end); 68 static ExpressionNode* makePostfixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end); 69 static PropertyNode* makeGetterOrSetterPropertyNode(void*, const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceCode&); 70 static ExpressionNodeInfo makeFunctionCallNode(void*, ExpressionNodeInfo func, ArgumentsNodeInfo, int start, int divot, int end); 71 static ExpressionNode* makeTypeOfNode(void*, ExpressionNode*); 72 static ExpressionNode* makeDeleteNode(void*, ExpressionNode*, int start, int divot, int end); 73 static ExpressionNode* makeNegateNode(void*, ExpressionNode*); 74 static NumberNode* makeNumberNode(void*, double); 75 static ExpressionNode* makeBitwiseNotNode(void*, ExpressionNode*); 76 static ExpressionNode* makeMultNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 77 static ExpressionNode* makeDivNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 78 static ExpressionNode* makeAddNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 79 static ExpressionNode* makeSubNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 80 static ExpressionNode* makeLeftShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 81 static ExpressionNode* makeRightShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 82 static StatementNode* makeVarStatementNode(void*, ExpressionNode*); 83 static ExpressionNode* combineVarInitializers(void*, ExpressionNode* list, AssignResolveNode* init); 66 static ExpressionNode* makeAssignNode(JSGlobalData*, ExpressionNode* loc, Operator, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end); 67 static ExpressionNode* makePrefixNode(JSGlobalData*, ExpressionNode* expr, Operator, int start, int divot, int end); 68 static ExpressionNode* makePostfixNode(JSGlobalData*, ExpressionNode* expr, Operator, int start, int divot, int end); 69 static PropertyNode* makeGetterOrSetterPropertyNode(JSGlobalData*, const Identifier& getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceCode&); 70 static ExpressionNodeInfo makeFunctionCallNode(JSGlobalData*, ExpressionNodeInfo func, ArgumentsNodeInfo, int start, int divot, int end); 71 static ExpressionNode* makeTypeOfNode(JSGlobalData*, ExpressionNode*); 72 static ExpressionNode* makeDeleteNode(JSGlobalData*, ExpressionNode*, int start, int divot, int end); 73 static ExpressionNode* makeNegateNode(JSGlobalData*, ExpressionNode*); 74 static NumberNode* makeNumberNode(JSGlobalData*, double); 75 static ExpressionNode* makeBitwiseNotNode(JSGlobalData*, ExpressionNode*); 76 static ExpressionNode* makeMultNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 77 static ExpressionNode* makeDivNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 78 static ExpressionNode* makeAddNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 79 static ExpressionNode* makeSubNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 80 static ExpressionNode* makeLeftShiftNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 81 static ExpressionNode* makeRightShiftNode(JSGlobalData*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); 82 static StatementNode* makeVarStatementNode(JSGlobalData*, ExpressionNode*); 83 static ExpressionNode* combineVarInitializers(JSGlobalData*, ExpressionNode* list, AssignResolveNode* init); 84 85 // FIXME: This used to be a macro and is still named like one. It should be renamed. 86 static inline void SET_EXCEPTION_LOCATION(ThrowableExpressionData* node, unsigned start, unsigned divot, unsigned end) 87 { 88 node->setExceptionSourceCode(divot, divot - start, end - divot); 89 } 84 90 85 91 #if COMPILER(MSVC) … … 100 106 #define YYLEX_PARAM globalPtr 101 107 102 template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserArenaData<DeclarationStacks::VarStack>* varDecls,103 ParserArenaData<DeclarationStacks::FunctionStack>* funcDecls,104 CodeFeatures info,105 108 template <typename T> inline NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, 109 ParserArenaData<DeclarationStacks::VarStack>* varDecls, 110 ParserArenaData<DeclarationStacks::FunctionStack>* funcDecls, 111 CodeFeatures info, int numConstants) 106 112 { 107 113 ASSERT((info & ~AllFeatures) == 0); … … 110 116 } 111 117 112 template <typename T> NodeInfo<T> createNodeInfo(T node, CodeFeatures info, int numConstants)118 template <typename T> NodeInfo<T> inline createNodeInfo(T node, CodeFeatures info, int numConstants) 113 119 { 114 120 ASSERT((info & ~AllFeatures) == 0); … … 136 142 } 137 143 138 static void appendToVarDeclarationList( void* globalPtr, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)144 static void appendToVarDeclarationList(JSGlobalData* globalData, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs) 139 145 { 140 146 if (!varDecls) 141 varDecls = new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::VarStack>; 142 143 varDecls->data.append(make_pair(ident, attrs)); 144 145 } 146 147 static inline void appendToVarDeclarationList(void* globalPtr, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl) 147 varDecls = new (globalData) ParserArenaData<DeclarationStacks::VarStack>; 148 149 varDecls->data.append(make_pair(&ident, attrs)); 150 } 151 152 static inline void appendToVarDeclarationList(JSGlobalData* globalData, ParserArenaData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl) 148 153 { 149 154 unsigned attrs = DeclarationStacks::IsConstant; 150 155 if (decl->hasInitializer()) 151 156 attrs |= DeclarationStacks::HasInitializer; 152 appendToVarDeclarationList(global Ptr, varDecls, decl->ident(), attrs);157 appendToVarDeclarationList(globalData, varDecls, decl->ident(), attrs); 153 158 } 154 159 … … 158 163 int intValue; 159 164 double doubleValue; 160 Identifier*ident;165 const Identifier* ident; 161 166 162 167 // expression subtrees … … 294 299 | STRING { $$ = createNodeInfo<ExpressionNode*>(new (GLOBAL_DATA) StringNode(GLOBAL_DATA, *$1), 0, 1); } 295 300 | '/' /* regexp */ { 296 Lexer& l = *LEXER; 297 if (!l.scanRegExp()) 301 const Identifier* pattern; 302 const Identifier* flags; 303 if (!LEXER->scanRegExp(pattern, flags)) 298 304 YYABORT; 299 RegExpNode* node = new (GLOBAL_DATA) RegExpNode(GLOBAL_DATA, l.pattern(), l.flags());300 int size = l.pattern().size() + 2; // + 2 for the two /'s305 RegExpNode* node = new (GLOBAL_DATA) RegExpNode(GLOBAL_DATA, *pattern, *flags); 306 int size = pattern->size() + 2; // + 2 for the two /'s 301 307 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size); 302 308 $$ = createNodeInfo<ExpressionNode*>(node, 0, 0); 303 309 } 304 310 | DIVEQUAL /* regexp with /= */ { 305 Lexer& l = *LEXER; 306 if (!l.scanRegExp()) 311 const Identifier* pattern; 312 const Identifier* flags; 313 if (!LEXER->scanRegExp(pattern, flags, '=')) 307 314 YYABORT; 308 RegExpNode* node = new (GLOBAL_DATA) RegExpNode(GLOBAL_DATA, "=" + l.pattern(), l.flags());309 int size = l.pattern().size() + 2; // + 2 for the two /'s315 RegExpNode* node = new (GLOBAL_DATA) RegExpNode(GLOBAL_DATA, *pattern, *flags); 316 int size = pattern->size() + 2; // + 2 for the two /'s 310 317 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size); 311 318 $$ = createNodeInfo<ExpressionNode*>(node, 0, 0); … … 316 323 IDENT ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); } 317 324 | STRING ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); } 318 | NUMBER ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, Identifier(GLOBAL_DATA, UString::from($1)), $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }319 | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode( globalPtr, *$1, *$2, 0, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); if (!$$.m_node) YYABORT; }325 | NUMBER ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new (GLOBAL_DATA) PropertyNode(GLOBAL_DATA, $1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); } 326 | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(GLOBAL_DATA, *$1, *$2, 0, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); if (!$$.m_node) YYABORT; } 320 327 | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 321 328 { 322 $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode( globalPtr, *$1, *$2, $4.m_node.head, $7, LEXER->sourceCode($6, $8, @6.first_line)), $4.m_features | ClosureFeature, 0);329 $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(GLOBAL_DATA, *$1, *$2, $4.m_node.head, $7, LEXER->sourceCode($6, $8, @6.first_line)), $4.m_features | ClosureFeature, 0); 323 330 if ($4.m_features & ArgumentsFeature) 324 331 $7->setUsesArguments(); … … 434 441 435 442 CallExpr: 436 MemberExpr Arguments { $$ = makeFunctionCallNode( globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }437 | CallExpr Arguments { $$ = makeFunctionCallNode( globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }443 MemberExpr Arguments { $$ = makeFunctionCallNode(GLOBAL_DATA, $1, $2, @1.first_column, @1.last_column, @2.last_column); } 444 | CallExpr Arguments { $$ = makeFunctionCallNode(GLOBAL_DATA, $1, $2, @1.first_column, @1.last_column, @2.last_column); } 438 445 | CallExpr '[' Expr ']' { BracketAccessorNode* node = new (GLOBAL_DATA) BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature); 439 446 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column); … … 446 453 447 454 CallExprNoBF: 448 MemberExprNoBF Arguments { $$ = makeFunctionCallNode( globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }449 | CallExprNoBF Arguments { $$ = makeFunctionCallNode( globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }455 MemberExprNoBF Arguments { $$ = makeFunctionCallNode(GLOBAL_DATA, $1, $2, @1.first_column, @1.last_column, @2.last_column); } 456 | CallExprNoBF Arguments { $$ = makeFunctionCallNode(GLOBAL_DATA, $1, $2, @1.first_column, @1.last_column, @2.last_column); } 450 457 | CallExprNoBF '[' Expr ']' { BracketAccessorNode* node = new (GLOBAL_DATA) BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature); 451 458 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column); … … 813 820 814 821 Block: 815 OPENBRACE CLOSEBRACE 822 OPENBRACE CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new (GLOBAL_DATA) BlockNode(GLOBAL_DATA, 0), 0, 0, 0, 0); 816 823 DBG($$.m_node, @1, @2); } 817 | OPENBRACE SourceElements CLOSEBRACE 824 | OPENBRACE SourceElements CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new (GLOBAL_DATA) BlockNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants); 818 825 DBG($$.m_node, @1, @3); } 819 826 ; … … 1242 1249 | TRUETOKEN 1243 1250 | FALSETOKEN 1244 | NUMBER { }1245 | STRING { }1246 | '/' /* regexp */ { Lexer& l = *LEXER; if (!l.scanRegExp()) YYABORT; }1247 | DIVEQUAL /* regexp with /= */ { Lexer& l = *LEXER; if (!l.scanRegExp()) YYABORT; }1251 | NUMBER 1252 | STRING 1253 | '/' /* regexp */ { if (!LEXER->skipRegExp()) YYABORT; } 1254 | DIVEQUAL /* regexp with /= */ { if (!LEXER->skipRegExp()) YYABORT; } 1248 1255 ; 1249 1256 1250 1257 Property_NoNode: 1251 IDENT ':' AssignmentExpr_NoNode { }1252 | STRING ':' AssignmentExpr_NoNode { }1253 | NUMBER ':' AssignmentExpr_NoNode { }1258 IDENT ':' AssignmentExpr_NoNode 1259 | STRING ':' AssignmentExpr_NoNode 1260 | NUMBER ':' AssignmentExpr_NoNode 1254 1261 | IDENT IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; } 1255 1262 | IDENT IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; } … … 1263 1270 PrimaryExpr_NoNode: 1264 1271 PrimaryExprNoBrace_NoNode 1265 | OPENBRACE CLOSEBRACE { }1266 | OPENBRACE PropertyList_NoNode CLOSEBRACE { }1272 | OPENBRACE CLOSEBRACE 1273 | OPENBRACE PropertyList_NoNode CLOSEBRACE 1267 1274 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */ 1268 | OPENBRACE PropertyList_NoNode ',' CLOSEBRACE { }1275 | OPENBRACE PropertyList_NoNode ',' CLOSEBRACE 1269 1276 ; 1270 1277 … … 1273 1280 | Literal_NoNode 1274 1281 | ArrayLiteral_NoNode 1275 | IDENT { }1282 | IDENT 1276 1283 | '(' Expr_NoNode ')' 1277 1284 ; … … 1641 1648 1642 1649 Block_NoNode: 1643 OPENBRACE CLOSEBRACE { }1644 | OPENBRACE SourceElements_NoNode CLOSEBRACE { }1650 OPENBRACE CLOSEBRACE 1651 | OPENBRACE SourceElements_NoNode CLOSEBRACE 1645 1652 ; 1646 1653 … … 1651 1658 1652 1659 VariableDeclarationList_NoNode: 1653 IDENT { }1654 | IDENT Initializer_NoNode { }1660 IDENT 1661 | IDENT Initializer_NoNode 1655 1662 | VariableDeclarationList_NoNode ',' IDENT 1656 1663 | VariableDeclarationList_NoNode ',' IDENT Initializer_NoNode … … 1658 1665 1659 1666 VariableDeclarationListNoIn_NoNode: 1660 IDENT { }1661 | IDENT InitializerNoIn_NoNode { }1667 IDENT 1668 | IDENT InitializerNoIn_NoNode 1662 1669 | VariableDeclarationListNoIn_NoNode ',' IDENT 1663 1670 | VariableDeclarationListNoIn_NoNode ',' IDENT InitializerNoIn_NoNode … … 1675 1682 1676 1683 ConstDeclaration_NoNode: 1677 IDENT { }1678 | IDENT Initializer_NoNode { }1684 IDENT 1685 | IDENT Initializer_NoNode 1679 1686 ; 1680 1687 … … 1752 1759 1753 1760 CaseBlock_NoNode: 1754 OPENBRACE CaseClausesOpt_NoNode CLOSEBRACE { }1755 | OPENBRACE CaseClausesOpt_NoNode DefaultClause_NoNode CaseClausesOpt_NoNode CLOSEBRACE { }1761 OPENBRACE CaseClausesOpt_NoNode CLOSEBRACE 1762 | OPENBRACE CaseClausesOpt_NoNode DefaultClause_NoNode CaseClausesOpt_NoNode CLOSEBRACE 1756 1763 ; 1757 1764 … … 1777 1784 1778 1785 LabelledStatement_NoNode: 1779 IDENT ':' Statement_NoNode { }1786 IDENT ':' Statement_NoNode 1780 1787 ; 1781 1788 … … 1809 1816 1810 1817 FormalParameterList_NoNode: 1811 IDENT { }1818 IDENT 1812 1819 | FormalParameterList_NoNode ',' IDENT 1813 1820 ; … … 1827 1834 %% 1828 1835 1829 static ExpressionNode* makeAssignNode(void* globalPtr, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end) 1836 #undef GLOBAL_DATA 1837 1838 static ExpressionNode* makeAssignNode(JSGlobalData* globalData, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end) 1830 1839 { 1831 1840 if (!loc->isLocation()) 1832 return new ( GLOBAL_DATA) AssignErrorNode(GLOBAL_DATA, loc, op, expr, divot, divot - start, end - divot);1841 return new (globalData) AssignErrorNode(globalData, loc, op, expr, divot, divot - start, end - divot); 1833 1842 1834 1843 if (loc->isResolveNode()) { 1835 1844 ResolveNode* resolve = static_cast<ResolveNode*>(loc); 1836 1845 if (op == OpEqual) { 1837 AssignResolveNode* node = new ( GLOBAL_DATA) AssignResolveNode(GLOBAL_DATA, resolve->identifier(), expr, exprHasAssignments);1846 AssignResolveNode* node = new (globalData) AssignResolveNode(globalData, resolve->identifier(), expr, exprHasAssignments); 1838 1847 SET_EXCEPTION_LOCATION(node, start, divot, end); 1839 1848 return node; 1840 1849 } else 1841 return new ( GLOBAL_DATA) ReadModifyResolveNode(GLOBAL_DATA, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);1850 return new (globalData) ReadModifyResolveNode(globalData, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot); 1842 1851 } 1843 1852 if (loc->isBracketAccessorNode()) { 1844 1853 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc); 1845 1854 if (op == OpEqual) 1846 return new ( GLOBAL_DATA) AssignBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot());1855 return new (globalData) AssignBracketNode(globalData, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot()); 1847 1856 else { 1848 ReadModifyBracketNode* node = new ( GLOBAL_DATA) ReadModifyBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot);1857 ReadModifyBracketNode* node = new (globalData) ReadModifyBracketNode(globalData, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot); 1849 1858 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset()); 1850 1859 return node; … … 1854 1863 DotAccessorNode* dot = static_cast<DotAccessorNode*>(loc); 1855 1864 if (op == OpEqual) 1856 return new ( GLOBAL_DATA) AssignDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot());1857 1858 ReadModifyDotNode* node = new ( GLOBAL_DATA) ReadModifyDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);1865 return new (globalData) AssignDotNode(globalData, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot()); 1866 1867 ReadModifyDotNode* node = new (globalData) ReadModifyDotNode(globalData, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot); 1859 1868 node->setSubexpressionInfo(dot->divot(), dot->endOffset()); 1860 1869 return node; 1861 1870 } 1862 1871 1863 static ExpressionNode* makePrefixNode( void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)1872 static ExpressionNode* makePrefixNode(JSGlobalData* globalData, ExpressionNode* expr, Operator op, int start, int divot, int end) 1864 1873 { 1865 1874 if (!expr->isLocation()) 1866 return new ( GLOBAL_DATA) PrefixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);1875 return new (globalData) PrefixErrorNode(globalData, expr, op, divot, divot - start, end - divot); 1867 1876 1868 1877 if (expr->isResolveNode()) { 1869 1878 ResolveNode* resolve = static_cast<ResolveNode*>(expr); 1870 return new ( GLOBAL_DATA) PrefixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);1879 return new (globalData) PrefixResolveNode(globalData, resolve->identifier(), op, divot, divot - start, end - divot); 1871 1880 } 1872 1881 if (expr->isBracketAccessorNode()) { 1873 1882 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr); 1874 PrefixBracketNode* node = new ( GLOBAL_DATA) PrefixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);1883 PrefixBracketNode* node = new (globalData) PrefixBracketNode(globalData, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot); 1875 1884 node->setSubexpressionInfo(bracket->divot(), bracket->startOffset()); 1876 1885 return node; … … 1878 1887 ASSERT(expr->isDotAccessorNode()); 1879 1888 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr); 1880 PrefixDotNode* node = new ( GLOBAL_DATA) PrefixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);1889 PrefixDotNode* node = new (globalData) PrefixDotNode(globalData, dot->base(), dot->identifier(), op, divot, divot - start, end - divot); 1881 1890 node->setSubexpressionInfo(dot->divot(), dot->startOffset()); 1882 1891 return node; 1883 1892 } 1884 1893 1885 static ExpressionNode* makePostfixNode( void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)1894 static ExpressionNode* makePostfixNode(JSGlobalData* globalData, ExpressionNode* expr, Operator op, int start, int divot, int end) 1886 1895 { 1887 1896 if (!expr->isLocation()) 1888 return new ( GLOBAL_DATA) PostfixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);1897 return new (globalData) PostfixErrorNode(globalData, expr, op, divot, divot - start, end - divot); 1889 1898 1890 1899 if (expr->isResolveNode()) { 1891 1900 ResolveNode* resolve = static_cast<ResolveNode*>(expr); 1892 return new ( GLOBAL_DATA) PostfixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);1901 return new (globalData) PostfixResolveNode(globalData, resolve->identifier(), op, divot, divot - start, end - divot); 1893 1902 } 1894 1903 if (expr->isBracketAccessorNode()) { 1895 1904 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr); 1896 PostfixBracketNode* node = new ( GLOBAL_DATA) PostfixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);1905 PostfixBracketNode* node = new (globalData) PostfixBracketNode(globalData, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot); 1897 1906 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset()); 1898 1907 return node; … … 1901 1910 ASSERT(expr->isDotAccessorNode()); 1902 1911 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr); 1903 PostfixDotNode* node = new ( GLOBAL_DATA) PostfixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);1912 PostfixDotNode* node = new (globalData) PostfixDotNode(globalData, dot->base(), dot->identifier(), op, divot, divot - start, end - divot); 1904 1913 node->setSubexpressionInfo(dot->divot(), dot->endOffset()); 1905 1914 return node; 1906 1915 } 1907 1916 1908 static ExpressionNodeInfo makeFunctionCallNode( void* globalPtr, ExpressionNodeInfo func, ArgumentsNodeInfo args, int start, int divot, int end)1917 static ExpressionNodeInfo makeFunctionCallNode(JSGlobalData* globalData, ExpressionNodeInfo func, ArgumentsNodeInfo args, int start, int divot, int end) 1909 1918 { 1910 1919 CodeFeatures features = func.m_features | args.m_features; 1911 1920 int numConstants = func.m_numConstants + args.m_numConstants; 1912 1921 if (!func.m_node->isLocation()) 1913 return createNodeInfo<ExpressionNode*>(new ( GLOBAL_DATA) FunctionCallValueNode(GLOBAL_DATA, func.m_node, args.m_node, divot, divot - start, end - divot), features, numConstants);1922 return createNodeInfo<ExpressionNode*>(new (globalData) FunctionCallValueNode(globalData, func.m_node, args.m_node, divot, divot - start, end - divot), features, numConstants); 1914 1923 if (func.m_node->isResolveNode()) { 1915 1924 ResolveNode* resolve = static_cast<ResolveNode*>(func.m_node); 1916 1925 const Identifier& identifier = resolve->identifier(); 1917 if (identifier == GLOBAL_DATA->propertyNames->eval)1918 return createNodeInfo<ExpressionNode*>(new ( GLOBAL_DATA) EvalFunctionCallNode(GLOBAL_DATA, args.m_node, divot, divot - start, end - divot), EvalFeature | features, numConstants);1919 return createNodeInfo<ExpressionNode*>(new ( GLOBAL_DATA) FunctionCallResolveNode(GLOBAL_DATA, identifier, args.m_node, divot, divot - start, end - divot), features, numConstants);1926 if (identifier == globalData->propertyNames->eval) 1927 return createNodeInfo<ExpressionNode*>(new (globalData) EvalFunctionCallNode(globalData, args.m_node, divot, divot - start, end - divot), EvalFeature | features, numConstants); 1928 return createNodeInfo<ExpressionNode*>(new (globalData) FunctionCallResolveNode(globalData, identifier, args.m_node, divot, divot - start, end - divot), features, numConstants); 1920 1929 } 1921 1930 if (func.m_node->isBracketAccessorNode()) { 1922 1931 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func.m_node); 1923 FunctionCallBracketNode* node = new ( GLOBAL_DATA) FunctionCallBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), args.m_node, divot, divot - start, end - divot);1932 FunctionCallBracketNode* node = new (globalData) FunctionCallBracketNode(globalData, bracket->base(), bracket->subscript(), args.m_node, divot, divot - start, end - divot); 1924 1933 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset()); 1925 1934 return createNodeInfo<ExpressionNode*>(node, features, numConstants); … … 1928 1937 DotAccessorNode* dot = static_cast<DotAccessorNode*>(func.m_node); 1929 1938 FunctionCallDotNode* node; 1930 if (dot->identifier() == GLOBAL_DATA->propertyNames->call)1931 node = new ( GLOBAL_DATA) CallFunctionCallDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot);1932 else if (dot->identifier() == GLOBAL_DATA->propertyNames->apply)1933 node = new ( GLOBAL_DATA) ApplyFunctionCallDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot);1939 if (dot->identifier() == globalData->propertyNames->call) 1940 node = new (globalData) CallFunctionCallDotNode(globalData, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot); 1941 else if (dot->identifier() == globalData->propertyNames->apply) 1942 node = new (globalData) ApplyFunctionCallDotNode(globalData, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot); 1934 1943 else 1935 node = new ( GLOBAL_DATA) FunctionCallDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot);1944 node = new (globalData) FunctionCallDotNode(globalData, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot); 1936 1945 node->setSubexpressionInfo(dot->divot(), dot->endOffset()); 1937 1946 return createNodeInfo<ExpressionNode*>(node, features, numConstants); 1938 1947 } 1939 1948 1940 static ExpressionNode* makeTypeOfNode( void* globalPtr, ExpressionNode* expr)1949 static ExpressionNode* makeTypeOfNode(JSGlobalData* globalData, ExpressionNode* expr) 1941 1950 { 1942 1951 if (expr->isResolveNode()) { 1943 1952 ResolveNode* resolve = static_cast<ResolveNode*>(expr); 1944 return new ( GLOBAL_DATA) TypeOfResolveNode(GLOBAL_DATA, resolve->identifier());1953 return new (globalData) TypeOfResolveNode(globalData, resolve->identifier()); 1945 1954 } 1946 return new ( GLOBAL_DATA) TypeOfValueNode(GLOBAL_DATA, expr);1947 } 1948 1949 static ExpressionNode* makeDeleteNode( void* globalPtr, ExpressionNode* expr, int start, int divot, int end)1955 return new (globalData) TypeOfValueNode(globalData, expr); 1956 } 1957 1958 static ExpressionNode* makeDeleteNode(JSGlobalData* globalData, ExpressionNode* expr, int start, int divot, int end) 1950 1959 { 1951 1960 if (!expr->isLocation()) 1952 return new ( GLOBAL_DATA) DeleteValueNode(GLOBAL_DATA, expr);1961 return new (globalData) DeleteValueNode(globalData, expr); 1953 1962 if (expr->isResolveNode()) { 1954 1963 ResolveNode* resolve = static_cast<ResolveNode*>(expr); 1955 return new ( GLOBAL_DATA) DeleteResolveNode(GLOBAL_DATA, resolve->identifier(), divot, divot - start, end - divot);1964 return new (globalData) DeleteResolveNode(globalData, resolve->identifier(), divot, divot - start, end - divot); 1956 1965 } 1957 1966 if (expr->isBracketAccessorNode()) { 1958 1967 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr); 1959 return new ( GLOBAL_DATA) DeleteBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), divot, divot - start, end - divot);1968 return new (globalData) DeleteBracketNode(globalData, bracket->base(), bracket->subscript(), divot, divot - start, end - divot); 1960 1969 } 1961 1970 ASSERT(expr->isDotAccessorNode()); 1962 1971 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr); 1963 return new ( GLOBAL_DATA) DeleteDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), divot, divot - start, end - divot);1964 } 1965 1966 static PropertyNode* makeGetterOrSetterPropertyNode( void* globalPtr, const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceCode& source)1972 return new (globalData) DeleteDotNode(globalData, dot->base(), dot->identifier(), divot, divot - start, end - divot); 1973 } 1974 1975 static PropertyNode* makeGetterOrSetterPropertyNode(JSGlobalData* globalData, const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceCode& source) 1967 1976 { 1968 1977 PropertyNode::Type type; … … 1973 1982 else 1974 1983 return 0; 1975 return new ( GLOBAL_DATA) PropertyNode(GLOBAL_DATA, name, new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type);1976 } 1977 1978 static ExpressionNode* makeNegateNode( void* globalPtr, ExpressionNode* n)1984 return new (globalData) PropertyNode(globalData, name, new FuncExprNode(globalData, globalData->propertyNames->nullIdentifier, body, source, params), type); 1985 } 1986 1987 static ExpressionNode* makeNegateNode(JSGlobalData* globalData, ExpressionNode* n) 1979 1988 { 1980 1989 if (n->isNumber()) { … … 1987 1996 } 1988 1997 1989 return new ( GLOBAL_DATA) NegateNode(GLOBAL_DATA, n);1990 } 1991 1992 static NumberNode* makeNumberNode( void* globalPtr, double d)1993 { 1994 return new ( GLOBAL_DATA) NumberNode(GLOBAL_DATA, d);1995 } 1996 1997 static ExpressionNode* makeBitwiseNotNode( void* globalPtr, ExpressionNode* expr)1998 return new (globalData) NegateNode(globalData, n); 1999 } 2000 2001 static NumberNode* makeNumberNode(JSGlobalData* globalData, double d) 2002 { 2003 return new (globalData) NumberNode(globalData, d); 2004 } 2005 2006 static ExpressionNode* makeBitwiseNotNode(JSGlobalData* globalData, ExpressionNode* expr) 1998 2007 { 1999 2008 if (expr->isNumber()) 2000 return makeNumberNode(global Ptr, ~toInt32(static_cast<NumberNode*>(expr)->value()));2001 return new ( GLOBAL_DATA) BitwiseNotNode(GLOBAL_DATA, expr);2002 } 2003 2004 static ExpressionNode* makeMultNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2009 return makeNumberNode(globalData, ~toInt32(static_cast<NumberNode*>(expr)->value())); 2010 return new (globalData) BitwiseNotNode(globalData, expr); 2011 } 2012 2013 static ExpressionNode* makeMultNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2005 2014 { 2006 2015 expr1 = expr1->stripUnaryPlus(); … … 2008 2017 2009 2018 if (expr1->isNumber() && expr2->isNumber()) 2010 return makeNumberNode(global Ptr, static_cast<NumberNode*>(expr1)->value() * static_cast<NumberNode*>(expr2)->value());2019 return makeNumberNode(globalData, static_cast<NumberNode*>(expr1)->value() * static_cast<NumberNode*>(expr2)->value()); 2011 2020 2012 2021 if (expr1->isNumber() && static_cast<NumberNode*>(expr1)->value() == 1) 2013 return new ( GLOBAL_DATA) UnaryPlusNode(GLOBAL_DATA, expr2);2022 return new (globalData) UnaryPlusNode(globalData, expr2); 2014 2023 2015 2024 if (expr2->isNumber() && static_cast<NumberNode*>(expr2)->value() == 1) 2016 return new ( GLOBAL_DATA) UnaryPlusNode(GLOBAL_DATA, expr1);2017 2018 return new ( GLOBAL_DATA) MultNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2019 } 2020 2021 static ExpressionNode* makeDivNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2025 return new (globalData) UnaryPlusNode(globalData, expr1); 2026 2027 return new (globalData) MultNode(globalData, expr1, expr2, rightHasAssignments); 2028 } 2029 2030 static ExpressionNode* makeDivNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2022 2031 { 2023 2032 expr1 = expr1->stripUnaryPlus(); … … 2025 2034 2026 2035 if (expr1->isNumber() && expr2->isNumber()) 2027 return makeNumberNode(global Ptr, static_cast<NumberNode*>(expr1)->value() / static_cast<NumberNode*>(expr2)->value());2028 return new ( GLOBAL_DATA) DivNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2029 } 2030 2031 static ExpressionNode* makeAddNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2036 return makeNumberNode(globalData, static_cast<NumberNode*>(expr1)->value() / static_cast<NumberNode*>(expr2)->value()); 2037 return new (globalData) DivNode(globalData, expr1, expr2, rightHasAssignments); 2038 } 2039 2040 static ExpressionNode* makeAddNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2032 2041 { 2033 2042 if (expr1->isNumber() && expr2->isNumber()) 2034 return makeNumberNode(global Ptr, static_cast<NumberNode*>(expr1)->value() + static_cast<NumberNode*>(expr2)->value());2035 return new ( GLOBAL_DATA) AddNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2036 } 2037 2038 static ExpressionNode* makeSubNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2043 return makeNumberNode(globalData, static_cast<NumberNode*>(expr1)->value() + static_cast<NumberNode*>(expr2)->value()); 2044 return new (globalData) AddNode(globalData, expr1, expr2, rightHasAssignments); 2045 } 2046 2047 static ExpressionNode* makeSubNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2039 2048 { 2040 2049 expr1 = expr1->stripUnaryPlus(); … … 2042 2051 2043 2052 if (expr1->isNumber() && expr2->isNumber()) 2044 return makeNumberNode(global Ptr, static_cast<NumberNode*>(expr1)->value() - static_cast<NumberNode*>(expr2)->value());2045 return new ( GLOBAL_DATA) SubNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2046 } 2047 2048 static ExpressionNode* makeLeftShiftNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2053 return makeNumberNode(globalData, static_cast<NumberNode*>(expr1)->value() - static_cast<NumberNode*>(expr2)->value()); 2054 return new (globalData) SubNode(globalData, expr1, expr2, rightHasAssignments); 2055 } 2056 2057 static ExpressionNode* makeLeftShiftNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2049 2058 { 2050 2059 if (expr1->isNumber() && expr2->isNumber()) 2051 return makeNumberNode(global Ptr, toInt32(static_cast<NumberNode*>(expr1)->value()) << (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));2052 return new ( GLOBAL_DATA) LeftShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2053 } 2054 2055 static ExpressionNode* makeRightShiftNode( void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)2060 return makeNumberNode(globalData, toInt32(static_cast<NumberNode*>(expr1)->value()) << (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f)); 2061 return new (globalData) LeftShiftNode(globalData, expr1, expr2, rightHasAssignments); 2062 } 2063 2064 static ExpressionNode* makeRightShiftNode(JSGlobalData* globalData, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) 2056 2065 { 2057 2066 if (expr1->isNumber() && expr2->isNumber()) 2058 return makeNumberNode(global Ptr, toInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));2059 return new ( GLOBAL_DATA) RightShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);2060 } 2061 2062 / * called by yyparse on error */2063 int yyerror(const char 2067 return makeNumberNode(globalData, toInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f)); 2068 return new (globalData) RightShiftNode(globalData, expr1, expr2, rightHasAssignments); 2069 } 2070 2071 // Called by yyparse on error. 2072 int yyerror(const char*) 2064 2073 { 2065 2074 return 1; 2066 2075 } 2067 2076 2068 / * may we automatically insert a semicolon ? */2077 // May we automatically insert a semicolon? 2069 2078 static bool allowAutomaticSemicolon(Lexer& lexer, int yychar) 2070 2079 { … … 2072 2081 } 2073 2082 2074 static ExpressionNode* combineVarInitializers( void* globalPtr, ExpressionNode* list, AssignResolveNode* init)2083 static ExpressionNode* combineVarInitializers(JSGlobalData* globalData, ExpressionNode* list, AssignResolveNode* init) 2075 2084 { 2076 2085 if (!list) 2077 2086 return init; 2078 return new ( GLOBAL_DATA) CommaNode(GLOBAL_DATA, list, init);2087 return new (globalData) CommaNode(globalData, list, init); 2079 2088 } 2080 2089 … … 2082 2091 // statements (which later get stripped out), because the actual 2083 2092 // declaration work is hoisted up to the start of the function body 2084 static StatementNode* makeVarStatementNode( void* globalPtr, ExpressionNode* expr)2093 static StatementNode* makeVarStatementNode(JSGlobalData* globalData, ExpressionNode* expr) 2085 2094 { 2086 2095 if (!expr) 2087 return new (GLOBAL_DATA) EmptyStatementNode(GLOBAL_DATA); 2088 return new (GLOBAL_DATA) VarStatementNode(GLOBAL_DATA, expr); 2089 } 2090 2091 #undef GLOBAL_DATA 2096 return new (globalData) EmptyStatementNode(globalData); 2097 return new (globalData) VarStatementNode(globalData, expr); 2098 } -
trunk/JavaScriptCore/parser/Lexer.cpp
r43361 r43642 142 142 } 143 143 144 void Lexer::setCode(const SourceCode& source) 145 { 144 void Lexer::setCode(const SourceCode& source, ParserArena& arena) 145 { 146 m_arena = &arena.identifierArena(); 147 146 148 m_lineNumber = source.firstLine(); 147 149 m_delimited = false; … … 205 207 } 206 208 207 ALWAYS_INLINE Identifier* Lexer::makeIdentifier(const UChar* characters, size_t length) 208 { 209 m_identifiers.append(Identifier(m_globalData, characters, length)); 210 return &m_identifiers.last(); 209 ALWAYS_INLINE const Identifier* Lexer::makeIdentifier(const UChar* characters, size_t length) 210 { 211 return &JSC::makeIdentifier(*m_arena, m_globalData, characters, length); 211 212 } 212 213 … … 909 910 } 910 911 911 bool Lexer::scanRegExp( )912 bool Lexer::scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar prefix) 912 913 { 913 914 ASSERT(m_buffer16.isEmpty()); 914 915 916 bool lastWasEscape = false; 917 bool inBrackets = false; 918 919 if (prefix) 920 record16(prefix); 921 922 while (true) { 923 if (isLineTerminator(m_current) || m_current == -1) { 924 m_buffer16.resize(0); 925 return false; 926 } 927 if (m_current != '/' || lastWasEscape || inBrackets) { 928 // keep track of '[' and ']' 929 if (!lastWasEscape) { 930 if (m_current == '[' && !inBrackets) 931 inBrackets = true; 932 if (m_current == ']' && inBrackets) 933 inBrackets = false; 934 } 935 record16(m_current); 936 lastWasEscape = !lastWasEscape && m_current == '\\'; 937 } else { // end of regexp 938 pattern = makeIdentifier(m_buffer16.data(), m_buffer16.size()); 939 m_buffer16.resize(0); 940 shift1(); 941 break; 942 } 943 shift1(); 944 } 945 946 while (isIdentPart(m_current)) { 947 record16(m_current); 948 shift1(); 949 } 950 flags = makeIdentifier(m_buffer16.data(), m_buffer16.size()); 951 m_buffer16.resize(0); 952 953 return true; 954 } 955 956 bool Lexer::skipRegExp() 957 { 915 958 bool lastWasEscape = false; 916 959 bool inBrackets = false; … … 927 970 inBrackets = false; 928 971 } 929 record16(m_current);930 972 lastWasEscape = !lastWasEscape && m_current == '\\'; 931 973 } else { // end of regexp 932 m_pattern = UString(m_buffer16); 933 m_buffer16.resize(0); 934 shift1(); 935 break; 936 } 937 shift1(); 938 } 939 940 while (isIdentPart(m_current)) { 941 record16(m_current); 942 shift1(); 943 } 944 m_flags = UString(m_buffer16); 945 m_buffer16.resize(0); 974 shift1(); 975 break; 976 } 977 shift1(); 978 } 979 980 while (isIdentPart(m_current)) 981 shift1(); 946 982 947 983 return true; … … 950 986 void Lexer::clear() 951 987 { 952 m_ identifiers.clear();988 m_arena = 0; 953 989 m_codeWithoutBOMs.clear(); 954 990 … … 962 998 963 999 m_isReparsing = false; 964 965 m_pattern = UString();966 m_flags = UString();967 1000 } 968 1001 -
trunk/JavaScriptCore/parser/Lexer.h
r43358 r43642 24 24 25 25 #include "Lookup.h" 26 #include " SegmentedVector.h"26 #include "ParserArena.h" 27 27 #include "SourceCode.h" 28 28 #include <wtf/ASCIICType.h> … … 43 43 44 44 // Functions to set up parsing. 45 void setCode(const SourceCode& );45 void setCode(const SourceCode&, ParserArena&); 46 46 void setIsReparsing() { m_isReparsing = true; } 47 47 … … 51 51 bool prevTerminator() const { return m_terminator; } 52 52 SourceCode sourceCode(int openBrace, int closeBrace, int firstLine); 53 bool scanRegExp(); 54 const UString& pattern() const { return m_pattern; } 55 const UString& flags() const { return m_flags; } 53 bool scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar prefix = 0); 54 bool skipRegExp(); 56 55 57 56 // Functions for use after parsing. … … 80 79 const UChar* currentCharacter() const; 81 80 82 JSC::Identifier* makeIdentifier(const UChar* buffer, size_t length);81 const Identifier* makeIdentifier(const UChar* characters, size_t length); 83 82 84 83 bool lastTokenWasRestrKeyword() const; 85 84 86 85 static const size_t initialReadBufferCapacity = 32; 87 static const size_t initialIdentifierTableCapacity = 64;88 86 89 87 int m_lineNumber; … … 109 107 int m_next3; 110 108 111 SegmentedVector<JSC::Identifier, initialIdentifierTableCapacity> m_identifiers;109 IdentifierArena* m_arena; 112 110 113 111 JSGlobalData* m_globalData; 114 115 UString m_pattern;116 UString m_flags;117 112 118 113 const HashTable m_keywordTable; -
trunk/JavaScriptCore/parser/NodeConstructors.h
r43488 r43642 28 28 namespace JSC { 29 29 30 inline void* ParserArenaFreeable::operator new(size_t size, JSGlobalData* globalData) 31 { 32 return globalData->parser->arena().allocateFreeable(size); 33 } 34 30 35 inline void* ParserArenaDeletable::operator new(size_t size, JSGlobalData* globalData) 31 36 { 32 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 33 globalData->parser->arena().deleteWithArena(deletable); 34 return deletable; 35 } 36 37 inline void* ParserArenaDeletable::operator new(size_t size) 38 { 39 return fastMalloc(size); 37 return globalData->parser->arena().allocateDeletable(size); 40 38 } 41 39 … … 79 77 } 80 78 81 inline StringNode::StringNode(JSGlobalData* globalData, const Identifier& v )79 inline StringNode::StringNode(JSGlobalData* globalData, const Identifier& value) 82 80 : ExpressionNode(globalData, ResultType::stringType()) 83 , m_value(v )84 { 85 } 86 87 inline RegExpNode::RegExpNode(JSGlobalData* globalData, const UString& pattern, const UString& flags)81 , m_value(value) 82 { 83 } 84 85 inline RegExpNode::RegExpNode(JSGlobalData* globalData, const Identifier& pattern, const Identifier& flags) 88 86 : ExpressionNode(globalData) 89 87 , m_pattern(pattern) … … 145 143 inline PropertyNode::PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* assign, Type type) 146 144 : m_name(name) 145 , m_assign(assign) 146 , m_type(type) 147 { 148 } 149 150 inline PropertyNode::PropertyNode(JSGlobalData* globalData, double name, ExpressionNode* assign, Type type) 151 : m_name(globalData->parser->arena().makeNumericIdentifier(globalData, name)) 147 152 , m_assign(assign) 148 153 , m_type(type) … … 737 742 inline ContinueNode::ContinueNode(JSGlobalData* globalData) 738 743 : StatementNode(globalData) 744 , m_ident(globalData->propertyNames->nullIdentifier) 739 745 { 740 746 } … … 748 754 inline BreakNode::BreakNode(JSGlobalData* globalData) 749 755 : StatementNode(globalData) 756 , m_ident(globalData->propertyNames->nullIdentifier) 750 757 { 751 758 } … … 826 833 } 827 834 828 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr )835 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* statements) 829 836 : m_expr(expr) 830 { 831 } 832 833 inline CaseClauseNode::CaseClauseNode(JSGlobalData*, ExpressionNode* expr, SourceElements* children) 834 : m_expr(expr) 835 { 836 if (children) 837 children->releaseContentsIntoVector(m_children); 837 , m_statements(statements) 838 { 838 839 } 839 840 … … 873 874 } 874 875 875 inline BlockNode::BlockNode(JSGlobalData* globalData, SourceElements* children) 876 : StatementNode(globalData) 877 { 878 if (children) 879 children->releaseContentsIntoVector(m_children); 876 inline BlockNode::BlockNode(JSGlobalData* globalData, SourceElements* statements) 877 : StatementNode(globalData) 878 , m_statements(statements) 879 { 880 880 } 881 881 882 882 inline ForInNode::ForInNode(JSGlobalData* globalData, ExpressionNode* l, ExpressionNode* expr, StatementNode* statement) 883 883 : StatementNode(globalData) 884 , m_ident(globalData->propertyNames->nullIdentifier) 884 885 , m_init(0) 885 886 , m_lexpr(l) -
trunk/JavaScriptCore/parser/Nodes.cpp
r43619 r43642 50 50 namespace JSC { 51 51 52 static void substitute(UString& string, const UString& substring) JSC_FAST_CALL; 52 /* 53 Details of the emitBytecode function. 54 55 Return value: The register holding the production's value. 56 dst: An optional parameter specifying the most efficient destination at 57 which to store the production's value. The callee must honor dst. 58 59 The dst argument provides for a crude form of copy propagation. For example, 60 61 x = 1 62 63 becomes 64 65 load r[x], 1 66 67 instead of 68 69 load r0, 1 70 mov r[x], r0 71 72 because the assignment node, "x =", passes r[x] as dst to the number node, "1". 73 */ 53 74 54 75 // ------------------------------ ThrowableExpressionData -------------------------------- … … 64 85 } 65 86 66 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType e, const char* msg)87 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* message) 67 88 { 68 89 generator.emitExpressionInfo(divot(), startOffset(), endOffset()); 69 RegisterID* exception = generator.emitNewError(generator.newTemporary(), e, jsString(generator.globalData(), msg));90 RegisterID* exception = generator.emitNewError(generator.newTemporary(), type, jsString(generator.globalData(), message)); 70 91 generator.emitThrow(exception); 71 92 return exception; 72 93 } 73 94 74 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType e, const char* msg, const Identifier& label)75 { 76 UString message = m sg;77 substitute(message, label .ustring());95 RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* messageTemplate, const UString& label) 96 { 97 UString message = messageTemplate; 98 substitute(message, label); 78 99 generator.emitExpressionInfo(divot(), startOffset(), endOffset()); 79 RegisterID* exception = generator.emitNewError(generator.newTemporary(), e, jsString(generator.globalData(), message));100 RegisterID* exception = generator.emitNewError(generator.newTemporary(), type, jsString(generator.globalData(), message)); 80 101 generator.emitThrow(exception); 81 102 return exception; 103 } 104 105 inline RegisterID* ThrowableExpressionData::emitThrowError(BytecodeGenerator& generator, ErrorType type, const char* messageTemplate, const Identifier& label) 106 { 107 return emitThrowError(generator, type, messageTemplate, label.ustring()); 82 108 } 83 109 … … 99 125 } 100 126 127 inline StatementNode* SourceElements::singleStatement() const 128 { 129 size_t size = m_statements.size(); 130 return size == 1 ? m_statements[0] : 0; 131 } 132 133 inline StatementNode* SourceElements::lastStatement() const 134 { 135 size_t size = m_statements.size(); 136 return size ? m_statements[size - 1] : 0; 137 } 138 101 139 // ------------------------------ NullNode ------------------------------------- 102 140 … … 139 177 RegisterID* RegExpNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 140 178 { 141 RefPtr<RegExp> regExp = RegExp::create(generator.globalData(), m_pattern , m_flags);179 RefPtr<RegExp> regExp = RegExp::create(generator.globalData(), m_pattern.ustring(), m_flags.ustring()); 142 180 if (!regExp->isValid()) 143 return emitThrowError(generator, SyntaxError, ("Invalid regular expression: " + UString(regExp->errorMessage())).UTF8String().c_str());181 return emitThrowError(generator, SyntaxError, "Invalid regular expression: %s", regExp->errorMessage()); 144 182 if (dst == generator.ignoredResult()) 145 183 return 0; … … 593 631 RegisterID* PostfixErrorNode::emitBytecode(BytecodeGenerator& generator, RegisterID*) 594 632 { 595 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus ? "Postfix ++ operator applied to value that is not a reference." : "Postfix -- operator applied to value that is not a reference."); 633 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus 634 ? "Postfix ++ operator applied to value that is not a reference." 635 : "Postfix -- operator applied to value that is not a reference."); 596 636 } 597 637 … … 755 795 RegisterID* PrefixErrorNode::emitBytecode(BytecodeGenerator& generator, RegisterID*) 756 796 { 757 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus ? "Prefix ++ operator applied to value that is not a reference." : "Prefix -- operator applied to value that is not a reference."); 797 return emitThrowError(generator, ReferenceError, m_operator == OpPlusPlus 798 ? "Prefix ++ operator applied to value that is not a reference." 799 : "Prefix -- operator applied to value that is not a reference."); 758 800 } 759 801 … … 1225 1267 } 1226 1268 1227 // ------------------------------ Helper functions for handling Vectors of StatementNode-------------------------------1228 1229 static inline void statementListEmitCode(const StatementVector& statements,BytecodeGenerator& generator, RegisterID* dst)1230 { 1231 size_t size = statements.size();1269 // ------------------------------ SourceElements ------------------------------- 1270 1271 inline void SourceElements::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1272 { 1273 size_t size = m_statements.size(); 1232 1274 for (size_t i = 0; i < size; ++i) 1233 generator.emitNode(dst, statements[i]);1275 generator.emitNode(dst, m_statements[i]); 1234 1276 } 1235 1277 1236 1278 // ------------------------------ BlockNode ------------------------------------ 1237 1279 1280 inline StatementNode* BlockNode::lastStatement() const 1281 { 1282 return m_statements ? m_statements->lastStatement() : 0; 1283 } 1284 1238 1285 RegisterID* BlockNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1239 1286 { 1240 statementListEmitCode(m_children, generator, dst); 1287 if (m_statements) 1288 m_statements->emitBytecode(generator, dst); 1241 1289 return 0; 1242 1290 } … … 1541 1589 generator.emitPopScope(); 1542 1590 return result; 1591 } 1592 1593 // ------------------------------ CaseClauseNode -------------------------------- 1594 1595 inline void CaseClauseNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 1596 { 1597 if (m_statements) 1598 m_statements->emitBytecode(generator, dst); 1543 1599 } 1544 1600 … … 1664 1720 for (ClauseListNode* list = m_list1; list; list = list->getNext()) { 1665 1721 generator.emitLabel(labelVector[i++].get()); 1666 statementListEmitCode(list->getClause()->children(),generator, dst);1722 list->getClause()->emitBytecode(generator, dst); 1667 1723 } 1668 1724 1669 1725 if (m_defaultClause) { 1670 1726 generator.emitLabel(defaultLabel.get()); 1671 statementListEmitCode(m_defaultClause->children(),generator, dst);1727 m_defaultClause->emitBytecode(generator, dst); 1672 1728 } 1673 1729 1674 1730 for (ClauseListNode* list = m_list2; list; list = list->getNext()) { 1675 1731 generator.emitLabel(labelVector[i++].get()); 1676 statementListEmitCode(list->getClause()->children(),generator, dst);1732 list->getClause()->emitBytecode(generator, dst); 1677 1733 } 1678 1734 if (!m_defaultClause) … … 1802 1858 // -----------------------------ScopeNodeData --------------------------- 1803 1859 1804 ScopeNodeData::ScopeNodeData(ParserArena& arena, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, int numConstants)1860 ScopeNodeData::ScopeNodeData(ParserArena& arena, SourceElements* statements, VarStack* varStack, FunctionStack* funcStack, int numConstants) 1805 1861 : m_numConstants(numConstants) 1862 , m_statements(statements) 1806 1863 { 1807 1864 m_arena.swap(arena); … … 1810 1867 if (funcStack) 1811 1868 m_functionStack.swap(*funcStack); 1812 if (children)1813 children->releaseContentsIntoVector(m_children);1814 1869 } 1815 1870 … … 1851 1906 } 1852 1907 1908 inline void ScopeNode::emitStatementsBytecode(BytecodeGenerator& generator, RegisterID* dst) 1909 { 1910 if (m_data->m_statements) 1911 m_data->m_statements->emitBytecode(generator, dst); 1912 } 1913 1914 inline StatementNode* ScopeNode::singleStatement() const 1915 { 1916 return m_data->m_statements ? m_data->m_statements->singleStatement() : 0; 1917 } 1918 1853 1919 // ------------------------------ ProgramNode ----------------------------- 1854 1920 … … 1875 1941 RefPtr<RegisterID> dstRegister = generator.newTemporary(); 1876 1942 generator.emitLoad(dstRegister.get(), jsUndefined()); 1877 statementListEmitCode(children(),generator, dstRegister.get());1943 emitStatementsBytecode(generator, dstRegister.get()); 1878 1944 1879 1945 generator.emitDebugHook(DidExecuteProgram, firstLine(), lastLine()); … … 1919 1985 RefPtr<RegisterID> dstRegister = generator.newTemporary(); 1920 1986 generator.emitLoad(dstRegister.get(), jsUndefined()); 1921 statementListEmitCode(children(),generator, dstRegister.get());1987 emitStatementsBytecode(generator, dstRegister.get()); 1922 1988 1923 1989 generator.emitDebugHook(DidExecuteProgram, firstLine(), lastLine()); … … 1937 2003 1938 2004 // Eval code needs to hang on to its declaration stacks to keep declaration info alive until Interpreter::execute time, 1939 // so the entire ScopeNodeData cannot be destoyed. 1940 children().clear(); 2005 // so the ScopeNodeData cannot be destroyed at this point. Maybe we can destroy part of it in the future? 1941 2006 } 1942 2007 … … 2092 2157 { 2093 2158 generator.emitDebugHook(DidEnterCallFrame, firstLine(), lastLine()); 2094 statementListEmitCode(children(), generator, generator.ignoredResult()); 2095 if (children().size() && children().last()->isBlock()) { 2096 BlockNode* blockNode = static_cast<BlockNode*>(children().last()); 2097 if (blockNode->children().size() && blockNode->children().last()->isReturnNode()) 2159 emitStatementsBytecode(generator, generator.ignoredResult()); 2160 StatementNode* singleStatement = this->singleStatement(); 2161 if (singleStatement && singleStatement->isBlock()) { 2162 StatementNode* lastStatementInBlock = static_cast<BlockNode*>(singleStatement)->lastStatement(); 2163 if (lastStatementInBlock && lastStatementInBlock->isReturnNode()) 2098 2164 return 0; 2099 2165 } -
trunk/JavaScriptCore/parser/Nodes.h
r43479 r43642 34 34 #include "SourceCode.h" 35 35 #include "SymbolTable.h" 36 #include <wtf/FastAllocBase.h> 36 37 #include <wtf/MathExtras.h> 37 38 #include <wtf/OwnPtr.h> … … 93 94 namespace DeclarationStacks { 94 95 enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; 95 typedef Vector<std::pair< Identifier, unsigned> > VarStack;96 typedef Vector<std::pair<const Identifier*, unsigned> > VarStack; 96 97 typedef Vector<FuncDeclNode*> FunctionStack; 97 98 } … … 103 104 }; 104 105 105 class ParserArenaDeletable { 106 protected: 107 ParserArenaDeletable() { } 108 106 class ParserArenaFreeable : public FastAllocBase { 107 public: 108 using FastAllocBase::operator new; 109 110 // Objects created with this version of new are freed when the arena is deleted. 111 // Destructors are not called. Clients must not call delete on such objects. 112 void* operator new(size_t, JSGlobalData*); 113 }; 114 115 class ParserArenaDeletable : public FastAllocBase { 109 116 public: 110 117 virtual ~ParserArenaDeletable() { } 111 118 119 using FastAllocBase::operator new; 120 112 121 // Objects created with this version of new are deleted when the arena is deleted. 122 // Clients must not call delete directly on such objects. 113 123 void* operator new(size_t, JSGlobalData*); 114 115 // Objects created with this version of new are not deleted when the arena is deleted.116 // Other arrangements must be made.117 void* operator new(size_t);118 124 }; 119 125 … … 129 135 }; 130 136 131 class Node : public ParserArena Deletable {137 class Node : public ParserArenaFreeable { 132 138 protected: 133 139 Node(JSGlobalData*); 134 140 135 141 public: 136 /* 137 Return value: The register holding the production's value. 138 dst: An optional parameter specifying the most efficient 139 destination at which to store the production's value. 140 The callee must honor dst. 141 142 dst provides for a crude form of copy propagation. For example, 143 144 x = 1 145 146 becomes 147 148 load r[x], 1 149 150 instead of 151 152 load r0, 1 153 mov r[x], r0 154 155 because the assignment node, "x =", passes r[x] as dst to the number 156 node, "1". 157 */ 142 virtual ~Node() { } 143 158 144 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* dst = 0) JSC_FAST_CALL = 0; 159 145 … … 249 235 class StringNode : public ExpressionNode { 250 236 public: 251 StringNode(JSGlobalData*, const Identifier& v);237 StringNode(JSGlobalData*, const Identifier&); 252 238 253 239 const Identifier& value() { return m_value; } 240 254 241 virtual bool isPure(BytecodeGenerator&) const JSC_FAST_CALL { return true; } 255 242 … … 259 246 virtual bool isString() const JSC_FAST_CALL { return true; } 260 247 261 Identifierm_value;248 const Identifier& m_value; 262 249 }; 263 250 … … 291 278 protected: 292 279 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg); 280 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const UString&); 293 281 RegisterID* emitThrowError(BytecodeGenerator&, ErrorType, const char* msg, const Identifier&); 294 282 … … 361 349 class RegExpNode : public ExpressionNode, public ThrowableExpressionData { 362 350 public: 363 RegExpNode(JSGlobalData*, const UString& pattern, const UString& flags);364 365 private: 366 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 367 368 UStringm_pattern;369 UStringm_flags;351 RegExpNode(JSGlobalData*, const Identifier& pattern, const Identifier& flags); 352 353 private: 354 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 355 356 const Identifier& m_pattern; 357 const Identifier& m_flags; 370 358 }; 371 359 … … 382 370 ResolveNode(JSGlobalData*, const Identifier&, int startOffset); 383 371 384 const Identifier& identifier() const JSC_FAST_CALL{ return m_ident; }372 const Identifier& identifier() const { return m_ident; } 385 373 386 374 private: … … 391 379 virtual bool isResolveNode() const JSC_FAST_CALL { return true; } 392 380 393 Identifierm_ident;381 const Identifier& m_ident; 394 382 int32_t m_startOffset; 395 383 }; 396 384 397 class ElementNode : public ParserArena Deletable {385 class ElementNode : public ParserArenaFreeable { 398 386 public: 399 387 ElementNode(JSGlobalData*, int elision, ExpressionNode*); … … 428 416 }; 429 417 430 class PropertyNode : public ParserArena Deletable {418 class PropertyNode : public ParserArenaFreeable { 431 419 public: 432 420 enum Type { Constant, Getter, Setter }; 433 421 434 422 PropertyNode(JSGlobalData*, const Identifier& name, ExpressionNode* value, Type); 423 PropertyNode(JSGlobalData*, double name, ExpressionNode* value, Type); 435 424 436 425 const Identifier& name() const { return m_name; } … … 438 427 private: 439 428 friend class PropertyListNode; 440 Identifierm_name;429 const Identifier& m_name; 441 430 ExpressionNode* m_assign; 442 431 Type m_type; … … 488 477 DotAccessorNode(JSGlobalData*, ExpressionNode* base, const Identifier&); 489 478 490 ExpressionNode* base() const JSC_FAST_CALL{ return m_base; }491 const Identifier& identifier() const JSC_FAST_CALL{ return m_ident; }479 ExpressionNode* base() const { return m_base; } 480 const Identifier& identifier() const { return m_ident; } 492 481 493 482 private: … … 498 487 499 488 ExpressionNode* m_base; 500 Identifierm_ident;489 const Identifier& m_ident; 501 490 }; 502 491 … … 513 502 }; 514 503 515 class ArgumentsNode : public ParserArena Deletable {504 class ArgumentsNode : public ParserArenaFreeable { 516 505 public: 517 506 ArgumentsNode(JSGlobalData*); … … 561 550 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 562 551 563 Identifierm_ident;552 const Identifier& m_ident; 564 553 ArgumentsNode* m_args; 565 554 size_t m_index; // Used by LocalVarFunctionCallNode. … … 588 577 protected: 589 578 ExpressionNode* m_base; 590 const Identifier m_ident;579 const Identifier& m_ident; 591 580 ArgumentsNode* m_args; 592 581 }; … … 613 602 614 603 protected: 615 const Identifier m_ident;604 const Identifier& m_ident; 616 605 }; 617 606 … … 646 635 647 636 ExpressionNode* m_base; 648 Identifierm_ident;637 const Identifier& m_ident; 649 638 Operator m_operator; 650 639 }; … … 668 657 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 669 658 670 Identifierm_ident;659 const Identifier& m_ident; 671 660 }; 672 661 … … 690 679 691 680 ExpressionNode* m_base; 692 Identifierm_ident;681 const Identifier& m_ident; 693 682 }; 694 683 … … 717 706 TypeOfResolveNode(JSGlobalData*, const Identifier&); 718 707 719 const Identifier& identifier() const JSC_FAST_CALL{ return m_ident; }720 721 private: 722 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 723 724 Identifierm_ident;708 const Identifier& identifier() const { return m_ident; } 709 710 private: 711 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 712 713 const Identifier& m_ident; 725 714 }; 726 715 … … 765 754 766 755 ExpressionNode* m_base; 767 Identifierm_ident;756 const Identifier& m_ident; 768 757 Operator m_operator; 769 758 }; … … 1007 996 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1008 997 1009 Identifierm_ident;998 const Identifier& m_ident; 1010 999 ExpressionNode* m_right; 1011 1000 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1021 1010 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1022 1011 1023 Identifierm_ident;1012 const Identifier& m_ident; 1024 1013 ExpressionNode* m_right; 1025 1014 size_t m_index; // Used by ReadModifyLocalVarNode. … … 1064 1053 1065 1054 ExpressionNode* m_base; 1066 Identifierm_ident;1055 const Identifier& m_ident; 1067 1056 ExpressionNode* m_right; 1068 1057 bool m_rightHasAssignments; … … 1077 1066 1078 1067 ExpressionNode* m_base; 1079 Identifierm_ident;1068 const Identifier& m_ident; 1080 1069 ExpressionNode* m_right; 1081 1070 Operator m_operator : 31; … … 1117 1106 virtual RegisterID* emitCodeSingle(BytecodeGenerator&) JSC_FAST_CALL; 1118 1107 1119 Identifierm_ident;1108 const Identifier& m_ident; 1120 1109 1121 1110 public: … … 1136 1125 }; 1137 1126 1138 typedef Vector<StatementNode*> StatementVector;1139 1140 1127 class SourceElements : public ParserArenaDeletable { 1141 1128 public: … … 1143 1130 1144 1131 void append(StatementNode*); 1145 void releaseContentsIntoVector(StatementVector& destination) 1146 { 1147 ASSERT(destination.isEmpty()); 1148 m_statements.swap(destination); 1149 destination.shrinkToFit(); 1150 } 1151 1152 private: 1153 StatementVector m_statements; 1132 1133 StatementNode* singleStatement() const; 1134 StatementNode* lastStatement() const; 1135 1136 void emitBytecode(BytecodeGenerator&, RegisterID* dst); 1137 1138 private: 1139 Vector<StatementNode*> m_statements; 1154 1140 }; 1155 1141 1156 1142 class BlockNode : public StatementNode { 1157 1143 public: 1158 BlockNode(JSGlobalData*, SourceElements* children);1159 1160 Statement Vector& children() { return m_children; }1144 BlockNode(JSGlobalData*, SourceElements* = 0); 1145 1146 StatementNode* lastStatement() const; 1161 1147 1162 1148 private: … … 1165 1151 virtual bool isBlock() const JSC_FAST_CALL { return true; } 1166 1152 1167 S tatementVector m_children;1153 SourceElements* m_statements; 1168 1154 }; 1169 1155 … … 1275 1261 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1276 1262 1277 Identifierm_ident;1263 const Identifier& m_ident; 1278 1264 ExpressionNode* m_init; 1279 1265 ExpressionNode* m_lexpr; … … 1291 1277 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1292 1278 1293 Identifierm_ident;1279 const Identifier& m_ident; 1294 1280 }; 1295 1281 … … 1302 1288 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1303 1289 1304 Identifierm_ident;1290 const Identifier& m_ident; 1305 1291 }; 1306 1292 … … 1337 1323 virtual RegisterID* emitBytecode(BytecodeGenerator&, RegisterID* = 0) JSC_FAST_CALL; 1338 1324 1339 Identifierm_name;1325 const Identifier& m_name; 1340 1326 StatementNode* m_statement; 1341 1327 }; … … 1359 1345 1360 1346 StatementNode* m_tryBlock; 1361 Identifierm_exceptionIdent;1347 const Identifier& m_exceptionIdent; 1362 1348 StatementNode* m_catchBlock; 1363 1349 StatementNode* m_finallyBlock; … … 1365 1351 }; 1366 1352 1367 class ParameterNode : public ParserArena Deletable {1353 class ParameterNode : public ParserArenaFreeable { 1368 1354 public: 1369 1355 ParameterNode(JSGlobalData*, const Identifier&); … … 1374 1360 1375 1361 private: 1376 Identifierm_ident;1362 const Identifier& m_ident; 1377 1363 ParameterNode* m_next; 1378 1364 }; … … 1388 1374 FunctionStack m_functionStack; 1389 1375 int m_numConstants; 1390 S tatementVector m_children;1376 SourceElements* m_statements; 1391 1377 1392 1378 void mark(); … … 1426 1412 FunctionStack& functionStack() { ASSERT(m_data); return m_data->m_functionStack; } 1427 1413 1428 StatementVector& children() { ASSERT(m_data); return m_data->m_children; }1429 1430 1414 int neededConstants() 1431 1415 { … … 1438 1422 virtual void mark() { } 1439 1423 1424 StatementNode* singleStatement() const; // 0 if there is not exactly one statement 1425 1440 1426 protected: 1441 1427 void setSource(const SourceCode& source) { m_source = source; } 1428 1429 void emitStatementsBytecode(BytecodeGenerator&, RegisterID* dst); 1442 1430 1443 1431 private: … … 1501 1489 virtual ~FunctionBodyNode(); 1502 1490 1503 const Identifier* parameters() const JSC_FAST_CALL{ return m_parameters; }1491 const Identifier* parameters() const { return m_parameters; } 1504 1492 size_t parameterCount() const { return m_parameterCount; } 1505 1493 UString paramString() const JSC_FAST_CALL; … … 1606 1594 }; 1607 1595 1608 class CaseClauseNode : public ParserArenaDeletable { 1609 public: 1610 CaseClauseNode(JSGlobalData*, ExpressionNode*); 1611 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements*); 1596 class CaseClauseNode : public ParserArenaFreeable { 1597 public: 1598 CaseClauseNode(JSGlobalData*, ExpressionNode*, SourceElements* = 0); 1612 1599 1613 1600 ExpressionNode* expr() const { return m_expr; } 1614 StatementVector& children() { return m_children; } 1615 1616 private: 1617 ExpressionNode* m_expr; 1618 StatementVector m_children; 1619 }; 1620 1621 class ClauseListNode : public ParserArenaDeletable { 1601 1602 void emitBytecode(BytecodeGenerator&, RegisterID* dst); 1603 1604 private: 1605 ExpressionNode* m_expr; 1606 SourceElements* m_statements; 1607 }; 1608 1609 class ClauseListNode : public ParserArenaFreeable { 1622 1610 public: 1623 1611 ClauseListNode(JSGlobalData*, CaseClauseNode*); … … 1632 1620 }; 1633 1621 1634 class CaseBlockNode : public ParserArena Deletable {1622 class CaseBlockNode : public ParserArenaFreeable { 1635 1623 public: 1636 1624 CaseBlockNode(JSGlobalData*, ClauseListNode* list1, CaseClauseNode* defaultClause, ClauseListNode* list2); -
trunk/JavaScriptCore/parser/Parser.cpp
r43479 r43642 54 54 55 55 Lexer& lexer = *globalData->lexer; 56 lexer.setCode(*m_source );56 lexer.setCode(*m_source, m_arena); 57 57 58 58 int parseError = jscyyparse(globalData); -
trunk/JavaScriptCore/parser/Parser.h
r43479 r43642 26 26 #include "Debugger.h" 27 27 #include "Nodes.h" 28 #include "ParserArena.h" 28 29 #include "SourceProvider.h" 29 30 #include <wtf/Forward.h> -
trunk/JavaScriptCore/parser/ParserArena.cpp
r43479 r43642 31 31 namespace JSC { 32 32 33 ParserArena::ParserArena() 34 : m_freeableMemory(0) 35 , m_freeablePoolEnd(0) 36 , m_identifierArena(new IdentifierArena) 37 { 38 } 39 40 inline void* ParserArena::freeablePool() 41 { 42 ASSERT(m_freeablePoolEnd); 43 return m_freeablePoolEnd - freeablePoolSize; 44 } 45 46 inline void ParserArena::deallocateObjects() 47 { 48 if (m_freeablePoolEnd) 49 fastFree(freeablePool()); 50 51 size_t size = m_freeablePools.size(); 52 for (size_t i = 0; i < size; ++i) 53 fastFree(m_freeablePools[i]); 54 55 size = m_deletableObjects.size(); 56 for (size_t i = 0; i < size; ++i) { 57 ParserArenaDeletable* object = m_deletableObjects[i]; 58 object->~ParserArenaDeletable(); 59 fastFree(object); 60 } 61 } 62 33 63 ParserArena::~ParserArena() 34 64 { 35 de leteAllValues(m_deletableObjects);65 deallocateObjects(); 36 66 } 37 67 … … 53 83 void ParserArena::reset() 54 84 { 55 deleteAllValues(m_deletableObjects); 56 m_deletableObjects.shrink(0); 57 m_refCountedObjects.shrink(0); 85 // Since this code path is used only when parsing fails, it's not bothering to reuse 86 // any of the memory the arena allocated. We could improve that later if we want to 87 // efficiently reuse the same arena. 88 89 deallocateObjects(); 90 91 m_freeableMemory = 0; 92 m_freeablePoolEnd = 0; 93 m_identifierArena->clear(); 94 m_freeablePools.clear(); 95 m_deletableObjects.clear(); 96 m_refCountedObjects.clear(); 97 } 98 99 const Identifier& ParserArena::makeNumericIdentifier(JSGlobalData* globalData, double number) 100 { 101 m_identifierArena->append(Identifier(globalData, UString::from(number))); 102 return m_identifierArena->last(); 103 } 104 105 void ParserArena::allocateFreeablePool() 106 { 107 if (m_freeablePoolEnd) 108 m_freeablePools.append(freeablePool()); 109 110 char* pool = static_cast<char*>(fastMalloc(freeablePoolSize)); 111 m_freeableMemory = pool; 112 m_freeablePoolEnd = pool + freeablePoolSize; 113 ASSERT(freeablePool() == pool); 114 } 115 116 bool ParserArena::isEmpty() const 117 { 118 return !m_freeablePoolEnd 119 && m_identifierArena->isEmpty() 120 && m_freeablePools.isEmpty() 121 && m_deletableObjects.isEmpty() 122 && m_refCountedObjects.isEmpty(); 58 123 } 59 124 -
trunk/JavaScriptCore/parser/ParserArena.h
r43479 r43642 27 27 #define ParserArena_h 28 28 29 #include <wtf/PassRefPtr.h> 30 #include <wtf/RefPtr.h> 31 #include <wtf/Vector.h> 29 #include "Identifier.h" 30 #include "SegmentedVector.h" 32 31 33 32 namespace JSC { … … 36 35 class ParserArenaRefCounted; 37 36 38 class ParserArena { 37 typedef SegmentedVector<Identifier, 64> IdentifierArena; 38 39 class ParserArena : Noncopyable { 39 40 public: 41 ParserArena(); 42 ~ParserArena(); 43 40 44 void swap(ParserArena& otherArena) 41 45 { 46 std::swap(m_freeableMemory, otherArena.m_freeableMemory); 47 std::swap(m_freeablePoolEnd, otherArena.m_freeablePoolEnd); 48 m_identifierArena.swap(otherArena.m_identifierArena); 49 m_freeablePools.swap(otherArena.m_freeablePools); 42 50 m_deletableObjects.swap(otherArena.m_deletableObjects); 43 51 m_refCountedObjects.swap(otherArena.m_refCountedObjects); 44 52 } 45 ~ParserArena();46 53 47 void deleteWithArena(ParserArenaDeletable* object) { m_deletableObjects.append(object); } 54 void* allocateFreeable(size_t size) 55 { 56 ASSERT(size); 57 ASSERT(size <= freeablePoolSize); 58 size_t alignedSize = alignSize(size); 59 ASSERT(alignedSize <= freeablePoolSize); 60 if (UNLIKELY(static_cast<size_t>(m_freeablePoolEnd - m_freeableMemory) < alignedSize)) 61 allocateFreeablePool(); 62 void* block = m_freeableMemory; 63 m_freeableMemory += alignedSize; 64 return block; 65 } 66 67 void* allocateDeletable(size_t size) 68 { 69 ParserArenaDeletable* deletable = static_cast<ParserArenaDeletable*>(fastMalloc(size)); 70 m_deletableObjects.append(deletable); 71 return deletable; 72 } 73 48 74 void derefWithArena(PassRefPtr<ParserArenaRefCounted> object) { m_refCountedObjects.append(object); } 49 50 75 bool contains(ParserArenaRefCounted*) const; 51 76 ParserArenaRefCounted* last() const; 52 77 void removeLast(); 53 78 54 bool isEmpty() const { return m_deletableObjects.isEmpty() && m_refCountedObjects.isEmpty(); }79 bool isEmpty() const; 55 80 void reset(); 56 81 82 const Identifier& makeIdentifier(JSGlobalData*, const UChar* character, size_t length); 83 const Identifier& makeNumericIdentifier(JSGlobalData*, double number); 84 85 IdentifierArena& identifierArena() { return *m_identifierArena; } 86 57 87 private: 88 static const size_t freeablePoolSize = 8000; 89 90 static size_t alignSize(size_t size) 91 { 92 return (size + sizeof(WTF::AllocAlignmentInteger) - 1) & ~(sizeof(WTF::AllocAlignmentInteger) - 1); 93 } 94 95 void* freeablePool(); 96 void allocateFreeablePool(); 97 void deallocateObjects(); 98 99 char* m_freeableMemory; 100 char* m_freeablePoolEnd; 101 102 OwnPtr<IdentifierArena> m_identifierArena; 103 Vector<void*> m_freeablePools; 58 104 Vector<ParserArenaDeletable*> m_deletableObjects; 59 105 Vector<RefPtr<ParserArenaRefCounted> > m_refCountedObjects; 60 106 }; 61 107 108 ALWAYS_INLINE const Identifier& makeIdentifier(IdentifierArena& arena, JSGlobalData* globalData, const UChar* characters, size_t length) 109 { 110 arena.append(Identifier(globalData, characters, length)); 111 return arena.last(); 112 } 113 114 ALWAYS_INLINE const Identifier& ParserArena::makeIdentifier(JSGlobalData* globalData, const UChar* characters, size_t length) 115 { 116 return JSC::makeIdentifier(*m_identifierArena, globalData, characters, length); 117 } 118 62 119 } 63 120
Note:
See TracChangeset
for help on using the changeset viewer.