Changeset 47089 in webkit for trunk/JavaScriptCore/parser
- Timestamp:
- Aug 11, 2009, 10:22:33 PM (16 years ago)
- Location:
- trunk/JavaScriptCore/parser
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/parser/Grammar.y
r45943 r47089 1168 1168 1169 1169 FunctionDeclaration: 1170 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::FunctionStack>, ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node) ); }1170 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new (GLOBAL_DATA) ParserArenaData<DeclarationStacks::FunctionStack>, ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)->body()); } 1171 1171 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 1172 1172 { … … 1175 1175 $7->setUsesArguments(); 1176 1176 DBG($7, @6, @8); 1177 $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node) );1177 $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)->body()); 1178 1178 } 1179 1179 ; -
trunk/JavaScriptCore/parser/NodeConstructors.h
r45730 r47089 815 815 inline FuncExprNode::FuncExprNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter) 816 816 : ExpressionNode(globalData) 817 , ParserArenaRefCounted(globalData)818 , m_ident(ident)819 817 , m_body(body) 820 818 { 821 m_body->finishParsing(source, parameter );819 m_body->finishParsing(source, parameter, ident); 822 820 } 823 821 824 822 inline FuncDeclNode::FuncDeclNode(JSGlobalData* globalData, const Identifier& ident, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter) 825 823 : StatementNode(globalData) 826 , ParserArenaRefCounted(globalData)827 , m_ident(ident)828 824 , m_body(body) 829 825 { 830 m_body->finishParsing(source, parameter );826 m_body->finishParsing(source, parameter, ident); 831 827 } 832 828 -
trunk/JavaScriptCore/parser/Nodes.cpp
r47062 r47089 1829 1829 FunctionStack::iterator end = m_functionStack.end(); 1830 1830 for (FunctionStack::iterator ptr = m_functionStack.begin(); ptr != end; ++ptr) { 1831 FunctionBodyNode* body = (*ptr)->body();1831 FunctionBodyNode* body = *ptr; 1832 1832 if (!body->isGenerated()) 1833 1833 continue; … … 2019 2019 } 2020 2020 2021 void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter )2021 void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident) 2022 2022 { 2023 2023 Vector<Identifier> parameters; … … 2027 2027 2028 2028 setSource(source); 2029 finishParsing(parameters.releaseBuffer(), count );2030 } 2031 2032 void FunctionBodyNode::finishParsing(Identifier* parameters, size_t parameterCount )2029 finishParsing(parameters.releaseBuffer(), count, ident); 2030 } 2031 2032 void FunctionBodyNode::finishParsing(Identifier* parameters, size_t parameterCount, const Identifier& ident) 2033 2033 { 2034 2034 ASSERT(!source().isNull()); 2035 2035 m_parameters = parameters; 2036 2036 m_parameterCount = parameterCount; 2037 m_ident = ident; 2037 2038 } 2038 2039 … … 2158 2159 // ------------------------------ FuncDeclNode --------------------------------- 2159 2160 2160 JSFunction* FuncDeclNode::makeFunction(ExecState* exec, ScopeChainNode* scopeChain)2161 {2162 return new (exec) JSFunction(exec, m_ident, m_body.get(), scopeChain);2163 }2164 2165 2161 RegisterID* FuncDeclNode::emitBytecode(BytecodeGenerator& generator, RegisterID* dst) 2166 2162 { … … 2177 2173 } 2178 2174 2179 JSFunction* FuncExprNode::makeFunction(ExecState* exec, ScopeChainNode* scopeChain)2180 {2181 JSFunction* func = new (exec) JSFunction(exec, m_ident, m_body.get(), scopeChain);2182 2183 /*2184 The Identifier in a FunctionExpression can be referenced from inside2185 the FunctionExpression's FunctionBody to allow the function to call2186 itself recursively. However, unlike in a FunctionDeclaration, the2187 Identifier in a FunctionExpression cannot be referenced from and2188 does not affect the scope enclosing the FunctionExpression.2189 */2190 2191 if (!m_ident.isNull()) {2192 JSStaticScopeObject* functionScopeObject = new (exec) JSStaticScopeObject(exec, m_ident, func, ReadOnly | DontDelete);2193 func->scope().push(functionScopeObject);2194 }2195 2196 return func;2197 }2198 2199 2175 } // namespace JSC -
trunk/JavaScriptCore/parser/Nodes.h
r47022 r47089 88 88 enum VarAttrs { IsConstant = 1, HasInitializer = 2 }; 89 89 typedef Vector<std::pair<Identifier, unsigned> > VarStack; 90 typedef Vector<Func DeclNode*> FunctionStack;90 typedef Vector<FunctionBodyNode*> FunctionStack; 91 91 } 92 92 … … 1566 1566 virtual void markAggregate(MarkStack&); 1567 1567 1568 void finishParsing(const SourceCode&, ParameterNode* );1569 void finishParsing(Identifier* parameters, size_t parameterCount );1568 void finishParsing(const SourceCode&, ParameterNode*, const Identifier& ident); 1569 void finishParsing(Identifier* parameters, size_t parameterCount, const Identifier& ident); 1570 1570 1571 1571 UString toSourceString() const { return source().toString(); } … … 1594 1594 return *m_code; 1595 1595 } 1596 1596 1597 const Identifier& ident() { return m_ident; } 1598 1599 JSFunction* make(ExecState*, ScopeChainNode*); 1600 1597 1601 private: 1598 1602 FunctionBodyNode(JSGlobalData*); … … 1603 1607 void generateJITCode(ScopeChainNode*); 1604 1608 #endif 1609 Identifier m_ident; 1605 1610 Identifier* m_parameters; 1606 1611 size_t m_parameterCount; … … 1608 1613 }; 1609 1614 1610 class FuncExprNode : public ExpressionNode , public ParserArenaRefCounted{1615 class FuncExprNode : public ExpressionNode { 1611 1616 public: 1612 1617 FuncExprNode(JSGlobalData*, const Identifier&, FunctionBodyNode* body, const SourceCode& source, ParameterNode* parameter = 0); 1613 1618 1614 JSFunction* makeFunction(ExecState*, ScopeChainNode*);1615 1616 1619 FunctionBodyNode* body() { return m_body.get(); } 1617 1620 … … 1621 1624 virtual bool isFuncExprNode() const { return true; } 1622 1625 1623 Identifier m_ident;1624 1626 RefPtr<FunctionBodyNode> m_body; 1625 1627 }; 1626 1628 1627 class FuncDeclNode : public StatementNode , public ParserArenaRefCounted{1629 class FuncDeclNode : public StatementNode { 1628 1630 public: 1629 1631 FuncDeclNode(JSGlobalData*, const Identifier&, FunctionBodyNode*, const SourceCode&, ParameterNode* = 0); 1630 1631 JSFunction* makeFunction(ExecState*, ScopeChainNode*);1632 1633 Identifier m_ident;1634 1632 1635 1633 FunctionBodyNode* body() { return m_body.get(); }
Note:
See TracChangeset
for help on using the changeset viewer.