Changeset 28855 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Dec 18, 2007, 11:42:49 PM (17 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/nodes.cpp
r28854 r28855 210 210 211 211 Node::Node() 212 : m_mayHaveDeclarations(false) 213 , m_expectedReturnType(ObjectType) 212 : m_expectedReturnType(ObjectType) 214 213 { 215 214 m_line = lexer().lineNo(); … … 217 216 218 217 Node::Node(JSType expectedReturn) 219 : m_mayHaveDeclarations(false) 220 , m_expectedReturnType(expectedReturn) 218 : m_expectedReturnType(expectedReturn) 221 219 { 222 220 m_line = lexer().lineNo(); … … 3451 3449 , init(in) 3452 3450 { 3453 m_mayHaveDeclarations = true;3454 3451 } 3455 3452 … … 3460 3457 if (init) 3461 3458 nodeStack.append(init.get()); 3462 }3463 3464 void VarDeclNode::getDeclarations(DeclarationStacks& stacks)3465 {3466 if (next) {3467 ASSERT(next->mayHaveDeclarations());3468 stacks.nodeStack.append(next.get());3469 }3470 3471 // The normal check to avoid overwriting pre-existing values with variable3472 // declarations doesn't work for the "arguments" property because we3473 // instantiate it lazily. So we need to check here instead.3474 if (ident == stacks.exec->propertyNames().arguments)3475 return;3476 3477 stacks.varStack.append(this);3478 3459 } 3479 3460 … … 3576 3557 } 3577 3558 3578 void VarStatementNode::getDeclarations(DeclarationStacks& stacks)3579 {3580 ASSERT(next->mayHaveDeclarations());3581 stacks.nodeStack.append(next.get());3582 }3583 3584 3559 // ------------------------------ Helper functions for handling Vectors of StatementNode ------------------------------- 3585 3560 … … 3592 3567 stack.append((*it).get()); 3593 3568 } 3594 }3595 3596 static inline void statementListGetDeclarations(SourceElements& statements, DeclarationStacks& stacks)3597 {3598 SourceElements::iterator it = statements.end();3599 SourceElements::iterator begin = statements.begin();3600 while (it != begin) {3601 --it;3602 if ((*it)->mayHaveDeclarations())3603 stacks.nodeStack.append((*it).get());3604 }3605 }3606 3607 static inline Node* statementListInitializeDeclarationStack(SourceElements& statements, DeclarationStacks::NodeStack& stack)3608 {3609 ASSERT(!stack.size()); // Otherwise, the removeLast() call might remove someone else's node.3610 3611 SourceElements::iterator it = statements.end();3612 SourceElements::iterator begin = statements.begin();3613 3614 while (it != begin) {3615 --it;3616 if ((*it)->mayHaveDeclarations())3617 stack.append((*it).get());3618 }3619 3620 if (!stack.size())3621 return 0;3622 3623 Node* n = stack.last();3624 stack.removeLast();3625 return n;3626 3569 } 3627 3570 … … 3667 3610 { 3668 3611 ASSERT(m_children); 3669 m_mayHaveDeclarations = true;3670 3612 } 3671 3613 … … 3673 3615 { 3674 3616 statementListPushFIFO(*m_children, nodeStack); 3675 }3676 3677 void BlockNode::getDeclarations(DeclarationStacks& stacks)3678 {3679 statementListGetDeclarations(*m_children, stacks);3680 3617 } 3681 3618 … … 3745 3682 } 3746 3683 3747 void IfNode::getDeclarations(DeclarationStacks& stacks)3748 {3749 if (statement2 && statement2->mayHaveDeclarations())3750 stacks.nodeStack.append(statement2.get());3751 if (statement1->mayHaveDeclarations())3752 stacks.nodeStack.append(statement1.get());3753 }3754 3755 3684 // ------------------------------ DoWhileNode ---------------------------------- 3756 3685 … … 3793 3722 3794 3723 return Completion(); // work around gcc 4.0 bug 3795 }3796 3797 void DoWhileNode::getDeclarations(DeclarationStacks& stacks)3798 {3799 if (statement->mayHaveDeclarations())3800 stacks.nodeStack.append(statement.get());3801 3724 } 3802 3725 … … 3841 3764 3842 3765 return Completion(); // work around gcc 4.0 bug 3843 }3844 3845 void WhileNode::getDeclarations(DeclarationStacks& stacks)3846 {3847 if (statement->mayHaveDeclarations())3848 stacks.nodeStack.append(statement.get());3849 3766 } 3850 3767 … … 3904 3821 } 3905 3822 3906 void ForNode::getDeclarations(DeclarationStacks& stacks)3907 {3908 if (statement->mayHaveDeclarations())3909 stacks.nodeStack.append(statement.get());3910 if (expr1 && expr1->mayHaveDeclarations())3911 stacks.nodeStack.append(expr1.get());3912 }3913 3914 3823 // ------------------------------ ForInNode ------------------------------------ 3915 3824 … … 3917 3826 : init(0L), lexpr(l), expr(e), varDecl(0L), statement(s) 3918 3827 { 3919 m_mayHaveDeclarations = true;3920 3828 } 3921 3829 … … 3923 3831 : ident(i), init(in), expr(e), statement(s) 3924 3832 { 3925 m_mayHaveDeclarations = true;3926 3927 3833 // for( var foo = bar in baz ) 3928 3834 varDecl = new VarDeclNode(ident, init.get(), VarDeclNode::Variable); … … 3937 3843 if (varDecl) 3938 3844 nodeStack.append(varDecl.get()); 3939 }3940 3941 void ForInNode::getDeclarations(DeclarationStacks& stacks)3942 {3943 if (statement->mayHaveDeclarations())3944 stacks.nodeStack.append(statement.get());3945 if (varDecl && varDecl->mayHaveDeclarations())3946 stacks.nodeStack.append(varDecl.get());3947 3845 } 3948 3846 … … 4103 4001 // ------------------------------ WithNode ------------------------------------- 4104 4002 4105 void WithNode::getDeclarations(DeclarationStacks& stacks)4106 {4107 if (statement->mayHaveDeclarations())4108 stacks.nodeStack.append(statement.get());4109 }4110 4111 4003 void WithNode::optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack& nodeStack) 4112 4004 { … … 4141 4033 } 4142 4034 4143 void CaseClauseNode::getDeclarations(DeclarationStacks& stacks)4144 {4145 if (m_children)4146 statementListGetDeclarations(*m_children, stacks);4147 }4148 4149 4035 // ECMA 12.11 4150 4036 JSValue *CaseClauseNode::evaluate(ExecState *exec) … … 4174 4060 } 4175 4061 4176 void ClauseListNode::getDeclarations(DeclarationStacks& stacks)4177 {4178 if (next && next->mayHaveDeclarations())4179 stacks.nodeStack.append(next.get());4180 if (clause->mayHaveDeclarations())4181 stacks.nodeStack.append(clause.get());4182 }4183 4184 4062 // ------------------------------ CaseBlockNode -------------------------------- 4185 4063 … … 4189 4067 , list2(l2) 4190 4068 { 4191 m_mayHaveDeclarations = true;4192 4069 } 4193 4070 … … 4200 4077 if (list1) 4201 4078 nodeStack.append(list1.get()); 4202 }4203 4204 void CaseBlockNode::getDeclarations(DeclarationStacks& stacks)4205 {4206 if (list2 && list2->mayHaveDeclarations())4207 stacks.nodeStack.append(list2.get());4208 if (def && def->mayHaveDeclarations())4209 stacks.nodeStack.append(def.get());4210 if (list1 && list1->mayHaveDeclarations())4211 stacks.nodeStack.append(list1.get());4212 4079 } 4213 4080 … … 4283 4150 } 4284 4151 4285 void SwitchNode::getDeclarations(DeclarationStacks& stacks)4286 {4287 if (block->mayHaveDeclarations())4288 stacks.nodeStack.append(block.get());4289 }4290 4291 4152 // ECMA 12.11 4292 4153 Completion SwitchNode::execute(ExecState *exec) … … 4311 4172 { 4312 4173 nodeStack.append(statement.get()); 4313 }4314 4315 void LabelNode::getDeclarations(DeclarationStacks& stacks)4316 {4317 if (statement->mayHaveDeclarations())4318 stacks.nodeStack.append(statement.get());4319 4174 } 4320 4175 … … 4359 4214 nodeStack.append(finallyBlock.get()); 4360 4215 nodeStack.append(tryBlock.get()); 4361 }4362 4363 void TryNode::getDeclarations(DeclarationStacks& stacks)4364 {4365 if (finallyBlock && finallyBlock->mayHaveDeclarations())4366 stacks.nodeStack.append(finallyBlock.get());4367 if (catchBlock && catchBlock->mayHaveDeclarations())4368 stacks.nodeStack.append(catchBlock.get());4369 if (tryBlock->mayHaveDeclarations())4370 stacks.nodeStack.append(tryBlock.get());4371 4216 } 4372 4217 … … 4612 4457 } 4613 4458 4614 void FuncDeclNode::getDeclarations(DeclarationStacks& stacks)4615 {4616 stacks.functionStack.append(this);4617 }4618 4619 4459 FunctionImp* FuncDeclNode::makeFunction(ExecState* exec) 4620 4460 { -
trunk/JavaScriptCore/kjs/nodes.h
r28854 r28855 139 139 virtual void streamTo(SourceStream&) const KJS_FAST_CALL = 0; 140 140 virtual Precedence precedence() const = 0; 141 142 // Used for iterative, depth-first traversal of the node tree. Does not cross function call boundaries.143 bool mayHaveDeclarations() const { return m_mayHaveDeclarations; }144 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL { ASSERT_NOT_REACHED(); }145 141 146 142 // Used for iterative, depth-first traversal of the node tree. Does not cross function call boundaries. … … 168 164 169 165 int m_line : 28; 170 bool m_mayHaveDeclarations : 1;171 166 unsigned m_expectedReturnType : 3; // JSType 172 167 }; … … 1715 1710 void evaluateSingle(ExecState*) KJS_FAST_CALL; 1716 1711 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1717 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1718 1712 virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; } 1719 1713 PassRefPtr<VarDeclNode> releaseNext() KJS_FAST_CALL { return next.release(); } … … 1729 1723 class VarStatementNode : public StatementNode { 1730 1724 public: 1731 VarStatementNode(VarDeclNode* l) KJS_FAST_CALL : next(l) { m_mayHaveDeclarations = true;}1725 VarStatementNode(VarDeclNode* l) KJS_FAST_CALL : next(l) { } 1732 1726 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1733 1727 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1734 1728 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1735 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1736 1729 private: 1737 1730 RefPtr<VarDeclNode> next; … … 1753 1746 virtual Completion execute(ExecState*) KJS_FAST_CALL { ASSERT_NOT_REACHED(); return Completion(); } 1754 1747 virtual void streamTo(SourceStream&) const KJS_FAST_CALL { ASSERT_NOT_REACHED(); } 1755 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL { ASSERT_NOT_REACHED(); }1756 1748 virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; } 1757 1749 private: … … 1765 1757 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1766 1758 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1767 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1768 1759 protected: 1769 1760 OwnPtr<SourceElements> m_children; … … 1790 1781 public: 1791 1782 IfNode(ExpressionNode* e, StatementNode *s1, StatementNode *s2) KJS_FAST_CALL 1792 : expr(e), statement1(s1), statement2(s2) { m_mayHaveDeclarations = statement1->mayHaveDeclarations() || (statement2 && statement2->mayHaveDeclarations());}1783 : expr(e), statement1(s1), statement2(s2) { } 1793 1784 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1794 1785 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1795 1786 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1796 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1797 1787 private: 1798 1788 RefPtr<ExpressionNode> expr; … … 1803 1793 class DoWhileNode : public StatementNode { 1804 1794 public: 1805 DoWhileNode(StatementNode *s, ExpressionNode* e) KJS_FAST_CALL : statement(s), expr(e) { m_mayHaveDeclarations = true;}1795 DoWhileNode(StatementNode *s, ExpressionNode* e) KJS_FAST_CALL : statement(s), expr(e) { } 1806 1796 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1807 1797 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1808 1798 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1809 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1810 1799 private: 1811 1800 RefPtr<StatementNode> statement; … … 1815 1804 class WhileNode : public StatementNode { 1816 1805 public: 1817 WhileNode(ExpressionNode* e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true;}1806 WhileNode(ExpressionNode* e, StatementNode *s) KJS_FAST_CALL : expr(e), statement(s) { } 1818 1807 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1819 1808 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1820 1809 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1821 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1822 1810 private: 1823 1811 RefPtr<ExpressionNode> expr; … … 1830 1818 expr1(e1), expr2(e2), expr3(e3), statement(s) 1831 1819 { 1832 m_mayHaveDeclarations = true;1833 1820 if (expr1) 1834 1821 expr1->optimizeForUnnecessaryResult(); … … 1840 1827 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1841 1828 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1842 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1843 1829 private: 1844 1830 RefPtr<ExpressionNode> expr1; … … 1855 1841 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1856 1842 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1857 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1858 1843 VarDeclNode* getVarDecl() { return varDecl.get(); } 1859 1844 private: … … 1898 1883 class WithNode : public StatementNode { 1899 1884 public: 1900 WithNode(ExpressionNode* e, StatementNode* s) KJS_FAST_CALL : expr(e), statement(s) { m_mayHaveDeclarations = true;}1885 WithNode(ExpressionNode* e, StatementNode* s) KJS_FAST_CALL : expr(e), statement(s) { } 1901 1886 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1902 1887 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1903 1888 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1904 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1905 1889 private: 1906 1890 RefPtr<ExpressionNode> expr; … … 1910 1894 class LabelNode : public StatementNode { 1911 1895 public: 1912 LabelNode(const Identifier &l, StatementNode *s) KJS_FAST_CALL : label(l), statement(s) { m_mayHaveDeclarations = true;}1896 LabelNode(const Identifier &l, StatementNode *s) KJS_FAST_CALL : label(l), statement(s) { } 1913 1897 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1914 1898 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1915 1899 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1916 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1917 1900 private: 1918 1901 Identifier label; … … 1933 1916 public: 1934 1917 TryNode(StatementNode *b, const Identifier &e, StatementNode *c, StatementNode *f) KJS_FAST_CALL 1935 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { m_mayHaveDeclarations = true;}1918 : tryBlock(b), exceptionIdent(e), catchBlock(c), finallyBlock(f) { } 1936 1919 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 1937 1920 virtual Completion execute(ExecState*) KJS_FAST_CALL; 1938 1921 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 1939 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;1940 1922 private: 1941 1923 RefPtr<StatementNode> tryBlock; … … 2037 2019 public: 2038 2020 FuncDeclNode(const Identifier& i, FunctionBodyNode* b) KJS_FAST_CALL 2039 : ident(i), body(b) { addParams(); m_mayHaveDeclarations = true;}2021 : ident(i), body(b) { addParams(); } 2040 2022 FuncDeclNode(const Identifier& i, ParameterNode* p, FunctionBodyNode* b) KJS_FAST_CALL 2041 : ident(i), param(p), body(b) { addParams(); m_mayHaveDeclarations = true;}2023 : ident(i), param(p), body(b) { addParams(); } 2042 2024 virtual Completion execute(ExecState*) KJS_FAST_CALL; 2043 2025 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 2044 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;2045 2026 ALWAYS_INLINE FunctionImp* makeFunction(ExecState*) KJS_FAST_CALL; 2046 2027 Identifier ident; … … 2053 2034 class CaseClauseNode : public Node { 2054 2035 public: 2055 CaseClauseNode(ExpressionNode* e) KJS_FAST_CALL : expr(e) { m_mayHaveDeclarations = true;}2036 CaseClauseNode(ExpressionNode* e) KJS_FAST_CALL : expr(e) { } 2056 2037 CaseClauseNode(ExpressionNode* e, SourceElements* children) KJS_FAST_CALL 2057 : expr(e), m_children(children) { m_mayHaveDeclarations = true;}2038 : expr(e), m_children(children) { } 2058 2039 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 2059 2040 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 2060 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;2061 2041 virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; } 2062 2042 … … 2071 2051 class ClauseListNode : public Node { 2072 2052 public: 2073 ClauseListNode(CaseClauseNode* c) KJS_FAST_CALL : clause(c) { m_mayHaveDeclarations = true;}2053 ClauseListNode(CaseClauseNode* c) KJS_FAST_CALL : clause(c) { } 2074 2054 ClauseListNode(ClauseListNode* n, CaseClauseNode* c) KJS_FAST_CALL 2075 : clause(c) { n->next = this; m_mayHaveDeclarations = true;}2055 : clause(c) { n->next = this; } 2076 2056 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 2077 2057 CaseClauseNode* getClause() const KJS_FAST_CALL { return clause.get(); } … … 2079 2059 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 2080 2060 PassRefPtr<ClauseListNode> releaseNext() KJS_FAST_CALL { return next.release(); } 2081 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;2082 2061 virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; } 2083 2062 private: … … 2093 2072 Completion evalBlock(ExecState *exec, JSValue *input) KJS_FAST_CALL; 2094 2073 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 2095 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;2096 2074 virtual Precedence precedence() const { ASSERT_NOT_REACHED(); return PrecExpression; } 2097 2075 private: … … 2103 2081 class SwitchNode : public StatementNode { 2104 2082 public: 2105 SwitchNode(ExpressionNode* e, CaseBlockNode *b) KJS_FAST_CALL : expr(e), block(b) { m_mayHaveDeclarations = true;}2083 SwitchNode(ExpressionNode* e, CaseBlockNode *b) KJS_FAST_CALL : expr(e), block(b) { } 2106 2084 virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL; 2107 2085 virtual Completion execute(ExecState*) KJS_FAST_CALL; 2108 2086 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 2109 virtual void getDeclarations(DeclarationStacks&) KJS_FAST_CALL;2110 2087 private: 2111 2088 RefPtr<ExpressionNode> expr;
Note:
See TracChangeset
for help on using the changeset viewer.