Changeset 43642 in webkit for trunk/JavaScriptCore/parser/Grammar.y
- Timestamp:
- May 13, 2009, 11:14:48 AM (16 years ago)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.