Changeset 27308 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp
- Timestamp:
- Oct 31, 2007, 3:54:37 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.cpp
r27255 r27308 2621 2621 } 2622 2622 2623 // ------------------------------ Helper functions for handling Vectors of StatementNode ------------------------------- 2624 2625 static inline void statementListPushFIFO(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack) 2626 { 2627 for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--) 2628 stack.append((*ptr).get()); 2629 } 2630 2631 static inline void statementListGetDeclarations(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks& stacks) 2632 { 2633 for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--) 2634 if ((*ptr)->mayHaveDeclarations()) 2635 stacks.nodeStack.append((*ptr).get()); 2636 } 2637 2638 static inline Node* statementListInitializeDeclarationStacks(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack) 2639 { 2640 for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--) 2641 if ((*ptr)->mayHaveDeclarations()) 2642 stack.append((*ptr).get()); 2643 if (!stack.size()) 2644 return 0; 2645 Node* n = stack.last(); 2646 stack.removeLast(); 2647 return n; 2648 } 2649 2650 static inline Node* statementListInitializeVariableAccessStack(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack) 2651 { 2652 for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr != statements.begin(); ptr--) 2653 stack.append((*ptr).get()); 2654 return statements[0].get(); 2655 } 2656 2657 static inline Completion statementListExecute(Vector<RefPtr<StatementNode> >& statements, ExecState *exec) 2658 { 2659 JSValue* v = 0; 2660 Completion c(Normal); 2661 const Vector<RefPtr<StatementNode> >::iterator end = statements.end(); 2662 for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.begin(); ptr != end; ptr++) { 2663 c = (*ptr)->execute(exec); 2664 2665 if (JSValue* v2 = c.value()) 2666 v = v2; 2667 c.setValue(v); 2668 2669 if (c.complType() != Normal) 2670 return c; 2671 } 2672 return c; 2673 } 2674 2623 2675 // ------------------------------ BlockNode ------------------------------------ 2624 2676 2625 2677 void BlockNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack) 2626 2678 { 2627 if ( source)2628 nodeStack.append(source.get());2629 } 2630 2631 BlockNode::BlockNode( SourceElementsNode* s)2632 { 2633 if ( s) {2679 if (m_children) 2680 statementListPushFIFO(*m_children, nodeStack); 2681 } 2682 2683 BlockNode::BlockNode(Vector<RefPtr<StatementNode> >* children) 2684 { 2685 if (children) { 2634 2686 m_mayHaveDeclarations = true; 2635 source = s; 2636 setLoc(s->firstLine(), s->lastLine()); 2637 } else { 2638 source = 0; 2687 m_children.set(children); 2688 setLoc(children->at(0)->firstLine(), children->at(children->size() - 1)->lastLine()); 2639 2689 } 2640 2690 } … … 2642 2692 void BlockNode::getDeclarations(DeclarationStacks& stacks) 2643 2693 { 2644 ASSERT( source && source->mayHaveDeclarations());2645 sta cks.nodeStack.append(source.get());2694 ASSERT(m_children); 2695 statementListGetDeclarations(*m_children, stacks); 2646 2696 } 2647 2697 … … 2649 2699 Completion BlockNode::execute(ExecState *exec) 2650 2700 { 2651 if (! source)2701 if (!m_children) 2652 2702 return Completion(Normal); 2653 2703 2654 return s ource->execute(exec);2704 return statementListExecute(*m_children, exec); 2655 2705 } 2656 2706 … … 3103 3153 return res; 3104 3154 } 3105 3155 3106 3156 // ------------------------------ CaseClauseNode ------------------------------- 3107 3157 … … 3110 3160 if (expr) 3111 3161 nodeStack.append(expr.get()); 3112 if ( source)3113 nodeStack.append(source.get());3162 if (m_children) 3163 statementListPushFIFO(*m_children, nodeStack); 3114 3164 } 3115 3165 3116 3166 void CaseClauseNode::getDeclarations(DeclarationStacks& stacks) 3117 3167 { 3118 if ( source && source->mayHaveDeclarations())3119 sta cks.nodeStack.append(source.get());3168 if (m_children) 3169 statementListGetDeclarations(*m_children, stacks); 3120 3170 } 3121 3171 … … 3132 3182 Completion CaseClauseNode::evalStatements(ExecState *exec) 3133 3183 { 3134 if ( source)3135 return s ource->execute(exec);3184 if (m_children) 3185 return statementListExecute(*m_children, exec); 3136 3186 else 3137 3187 return Completion(Normal, jsUndefined()); … … 3395 3445 // ------------------------------ FunctionBodyNode ----------------------------- 3396 3446 3397 FunctionBodyNode::FunctionBodyNode( SourceElementsNode* s)3398 : BlockNode( s)3447 FunctionBodyNode::FunctionBodyNode(Vector<RefPtr<StatementNode> > *children) 3448 : BlockNode(children) 3399 3449 , m_sourceURL(Lexer::curr()->sourceURL()) 3400 3450 , m_sourceId(Parser::sid) … … 3408 3458 void FunctionBodyNode::initializeDeclarationStacks(ExecState* exec) 3409 3459 { 3410 Node* node = source.get(); 3460 if (!m_children) 3461 return; 3462 3463 DeclarationStacks::NodeStack nodeStack; 3464 DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack); 3465 Node* node = statementListInitializeDeclarationStacks(*m_children, nodeStack); 3411 3466 if (!node) 3412 3467 return; 3413 3414 DeclarationStacks::NodeStack nodeStack;3415 DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack);3416 3468 3417 3469 while (true) { … … 3450 3502 void FunctionBodyNode::optimizeVariableAccess() 3451 3503 { 3452 Node* node = source.get(); 3504 if (!m_children) 3505 return; 3506 3507 DeclarationStacks::NodeStack nodeStack; 3508 Node* node = statementListInitializeVariableAccessStack(*m_children, nodeStack); 3453 3509 if (!node) 3454 3510 return; 3455 3456 DeclarationStacks::NodeStack nodeStack; 3457 3511 3458 3512 while (true) { 3459 3513 node->optimizeVariableAccess(this, nodeStack); … … 3632 3686 } 3633 3687 3634 // ------------------------------ SourceElementsNode --------------------------- 3635 3636 int SourceElementsNode::count = 0; 3637 3638 SourceElementsNode::SourceElementsNode(StatementNode* s1) 3639 : node(s1) 3640 { 3641 m_mayHaveDeclarations = true; 3642 setLoc(s1->firstLine(), s1->lastLine()); 3643 } 3644 3645 SourceElementsNode::SourceElementsNode(SourceElementsNode* s1, StatementNode* s2) 3646 : node(s2) 3647 { 3648 m_mayHaveDeclarations = true; 3649 s1->next = this; 3650 setLoc(s1->firstLine(), s2->lastLine()); 3651 } 3652 3653 void SourceElementsNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack) 3654 { 3655 if (next) 3656 nodeStack.append(next.get()); 3657 nodeStack.append(node.get()); 3658 } 3659 3660 void SourceElementsNode::getDeclarations(DeclarationStacks& stacks) 3661 { 3662 if (next && next->mayHaveDeclarations()) 3663 stacks.nodeStack.append(next.get()); 3664 if (node->mayHaveDeclarations()) 3665 stacks.nodeStack.append(node.get()); 3666 } 3667 3668 // ECMA 14 3669 Completion SourceElementsNode::execute(ExecState *exec) 3670 { 3671 JSValue* v = 0; 3672 SourceElementsNode* n = this; 3673 while (1) { 3674 Completion c = n->node->execute(exec); 3675 3676 if (JSValue* v2 = c.value()) 3677 v = v2; 3678 c.setValue(v); 3679 3680 if (c.complType() != Normal) 3681 return c; 3682 3683 n = n->next.get(); 3684 if (!n) 3685 return c; 3686 } 3687 } 3688 3689 ProgramNode::ProgramNode(SourceElementsNode* s) 3690 : FunctionBodyNode(s) 3691 { 3692 } 3693 3694 } 3688 ProgramNode::ProgramNode(Vector<RefPtr<StatementNode> >* children) 3689 : FunctionBodyNode(children) 3690 { 3691 } 3692 3693 }
Note:
See TracChangeset
for help on using the changeset viewer.