From: mjs@apple.com Date: Wed, 8 Oct 2008 00:15:20 +0000 (+0000) Subject: 2008-10-07 Maciej Stachowiak X-Git-Url: https://git.webkit.org/?p=WebKit.git;a=commitdiff_plain;h=54775182c246b9c2e1d335076f5bee44788a2216;hp=db499be26d2f3a4190fde0a21973f842da605a50 2008-10-07 Maciej Stachowiak Reviewed by Oliver Hunt. - make constant folding code more consistent Added a makeSubNode to match add, mult and div; use the makeFooNode functions always, instead of allocating nodes directly in other places in the grammar. * kjs/grammar.y: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37402 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog index 157ea502e8c8..67af2916d2ce 100644 --- a/JavaScriptCore/ChangeLog +++ b/JavaScriptCore/ChangeLog @@ -1,3 +1,14 @@ +2008-10-07 Maciej Stachowiak + + Reviewed by Oliver Hunt. + + - make constant folding code more consistent + + Added a makeSubNode to match add, mult and div; use the makeFooNode functions always, + instead of allocating nodes directly in other places in the grammar. + + * kjs/grammar.y: + 2008-10-07 Sam Weinig Reviewed by Cameron Zwarich. diff --git a/JavaScriptCore/kjs/grammar.y b/JavaScriptCore/kjs/grammar.y index 914ab823c27b..81e84b37d312 100644 --- a/JavaScriptCore/kjs/grammar.y +++ b/JavaScriptCore/kjs/grammar.y @@ -76,6 +76,7 @@ static ExpressionNode* makeBitwiseNotNode(void*, ExpressionNode*); static ExpressionNode* makeMultNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); static ExpressionNode* makeDivNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); static ExpressionNode* makeAddNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); +static ExpressionNode* makeSubNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); static ExpressionNode* makeLeftShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); static ExpressionNode* makeRightShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments); static StatementNode* makeVarStatementNode(void*, ExpressionNode*); @@ -524,9 +525,9 @@ MultiplicativeExpr: MultiplicativeExprNoBF: UnaryExprNoBF | MultiplicativeExprNoBF '*' UnaryExpr - { $$ = createNodeInfo(new MultNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + { $$ = createNodeInfo(makeMultNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } | MultiplicativeExprNoBF '/' UnaryExpr - { $$ = createNodeInfo(new DivNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + { $$ = createNodeInfo(makeDivNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } | MultiplicativeExprNoBF '%' UnaryExpr { $$ = createNodeInfo(new ModNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } ; @@ -534,15 +535,15 @@ MultiplicativeExprNoBF: AdditiveExpr: MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr { $$ = createNodeInfo(makeAddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } - | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeInfo(new SubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeInfo(makeSubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } ; AdditiveExprNoBF: MultiplicativeExprNoBF | AdditiveExprNoBF '+' MultiplicativeExpr - { $$ = createNodeInfo(new AddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + { $$ = createNodeInfo(makeAddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } | AdditiveExprNoBF '-' MultiplicativeExpr - { $$ = createNodeInfo(new SubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + { $$ = createNodeInfo(makeSubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } ; ShiftExpr: @@ -554,8 +555,8 @@ ShiftExpr: ShiftExprNoBF: AdditiveExprNoBF - | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = createNodeInfo(new LeftShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } - | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = createNodeInfo(new RightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = createNodeInfo(makeLeftShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } + | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = createNodeInfo(makeRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = createNodeInfo(new UnsignedRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); } ; @@ -1442,6 +1443,13 @@ static ExpressionNode* makeAddNode(void* globalPtr, ExpressionNode* expr1, Expre return new AddNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments); } +static ExpressionNode* makeSubNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) +{ + if (expr1->isNumber() && expr2->isNumber()) + return makeNumberNode(globalPtr, static_cast(expr1)->value() - static_cast(expr2)->value()); + return new SubNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments); +} + static ExpressionNode* makeLeftShiftNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments) { if (expr1->isNumber() && expr2->isNumber())