Ignore:
Timestamp:
Dec 4, 2014, 3:47:49 PM (10 years ago)
Author:
[email protected]
Message:

Split out FunctionNode from FunctionBodyNode
https://bugs.webkit.org/show_bug.cgi?id=139273

Reviewed by Andreas Kling.

This is step toward a parser speedup.

We used to use FunctionBodyNode for two different purposes:

(1) "I am the root function you are currently parsing";

(2) "I am a lazy record of a nested function, which you will parse later".

This made for awkward lifetime semantics and interfaces.

Now, case (1) is handled by FunctionBodyNode, and case (2) is handled by
a new node named FunctionNode.

Since case (1) no longer needs to handle being the root of the parse
tree, FunctionBodyNode can be a normal arena-allocated node.

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::generateFunctionCodeBlock): Use FunctionNode instead of
FunctionBodyNode, since we are producing the root of the function parse
tree.

(JSC::UnlinkedFunctionExecutable::UnlinkedFunctionExecutable): Removed
some unused data, and default-initialized other data, which isn't filled
in meaningfully until recordParse() is called. (The previous values were
incorrect / meaningless, since the FunctionBodyNode didn't have
meaningful values in this case.)

  • bytecode/UnlinkedCodeBlock.h: Ditto.

(JSC::UnlinkedFunctionExecutable::forceUsesArguments): Deleted.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator): Use FunctionNode instead of
FunctionBodyNode, since we are generating code starting at the root of
the parse tree.

(JSC::BytecodeGenerator::resolveCallee):
(JSC::BytecodeGenerator::addCallee):

  • bytecompiler/BytecodeGenerator.h: Ditto.
  • bytecompiler/NodesCodegen.cpp:

(JSC::FunctionBodyNode::emitBytecode):
(JSC::FunctionNode::emitBytecode): Moved the emitBytecode implementation
to FunctionNode, since we never generate code for FunctionBodyNode,
since it's just a placeholder in the AST.

  • parser/ASTBuilder.h:

(JSC::ASTBuilder::createFunctionBody):
(JSC::ASTBuilder::setUsesArguments): Deleted. Updated for interface
changes.

  • parser/Nodes.cpp:

(JSC::FunctionBodyNode::FunctionBodyNode):
(JSC::FunctionBodyNode::finishParsing):
(JSC::FunctionBodyNode::setEndPosition):
(JSC::FunctionNode::FunctionNode):
(JSC::FunctionNode::create):
(JSC::FunctionNode::finishParsing):
(JSC::FunctionBodyNode::create): Deleted.

  • parser/Nodes.h:

(JSC::FunctionBodyNode::parameters):
(JSC::FunctionBodyNode::source):
(JSC::FunctionBodyNode::startStartOffset):
(JSC::FunctionBodyNode::isInStrictContext):
(JSC::FunctionNode::parameters):
(JSC::FunctionNode::ident):
(JSC::FunctionNode::functionMode):
(JSC::FunctionNode::startColumn):
(JSC::FunctionNode::endColumn):
(JSC::ScopeNode::setSource): Deleted.
(JSC::FunctionBodyNode::parameterCount): Deleted. Split out the differences
between FunctionNode and FunctionBodyNode.

  • parser/SyntaxChecker.h:

(JSC::SyntaxChecker::createClauseList):
(JSC::SyntaxChecker::setUsesArguments): Deleted. Removed setUsesArguments
since it wasn't used.

  • runtime/Executable.cpp:

(JSC::ProgramExecutable::checkSyntax): Removed a branch that was always
false.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Nodes.cpp

    r176756 r176822  
    188188}
    189189
    190 inline FunctionBodyNode::FunctionBodyNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, bool inStrictContext)
    191     : ScopeNode(parserArena, startLocation, endLocation, inStrictContext)
     190FunctionBodyNode::FunctionBodyNode(ParserArena&, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, bool isInStrictContext)
     191    : StatementNode(endLocation)
    192192    , m_startColumn(startColumn)
    193193    , m_endColumn(endColumn)
    194 {
    195 }
    196 
    197 inline FunctionBodyNode::FunctionBodyNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
     194    , m_startStartOffset(startLocation.startOffset)
     195    , m_isInStrictContext(isInStrictContext)
     196{
     197}
     198
     199void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident, enum FunctionMode functionMode)
     200{
     201    m_source = source;
     202    m_parameters = FunctionParameters::create(firstParameter);
     203    m_ident = ident;
     204    m_functionMode = functionMode;
     205}
     206
     207void FunctionBodyNode::setEndPosition(JSTextPosition position)
     208{
     209    m_lastLine = position.line;
     210    m_endColumn = position.offset - position.lineStartOffset;
     211}
     212
     213// =====================
     214
     215inline FunctionNode::FunctionNode(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
    198216    : ScopeNode(parserArena, startLocation, endLocation, sourceCode, children, varStack, funcStack, capturedVariables, features, numConstants)
    199217    , m_startColumn(startColumn)
     
    202220}
    203221
    204 void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident, enum FunctionMode functionMode)
    205 {
    206     setSource(source);
    207     finishParsing(FunctionParameters::create(firstParameter), ident, functionMode);
    208 }
    209 
    210 void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident, enum FunctionMode functionMode)
     222PassRefPtr<FunctionNode> FunctionNode::create(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
     223{
     224    RefPtr<FunctionNode> node = new FunctionNode(parserArena, startLocation, endLocation, startColumn, endColumn , children, varStack, funcStack, capturedVariables, sourceCode, features, numConstants);
     225
     226    ASSERT(node->m_arena.last() == node);
     227    node->m_arena.removeLast();
     228    ASSERT(!node->m_arena.contains(node.get()));
     229
     230    return node.release();
     231}
     232
     233void FunctionNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident, enum FunctionMode functionMode)
    211234{
    212235    ASSERT(!source().isNull());
     
    216239}
    217240
    218 FunctionBodyNode* FunctionBodyNode::create(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, bool inStrictContext)
    219 {
    220     return new FunctionBodyNode(parserArena, startLocation, endLocation, startColumn, endColumn, inStrictContext);
    221 }
    222 
    223 PassRefPtr<FunctionBodyNode> FunctionBodyNode::create(ParserArena& parserArena, const JSTokenLocation& startLocation, const JSTokenLocation& endLocation, unsigned startColumn, unsigned endColumn, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, IdentifierSet& capturedVariables, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
    224 {
    225     RefPtr<FunctionBodyNode> node = new FunctionBodyNode(parserArena, startLocation, endLocation, startColumn, endColumn , children, varStack, funcStack, capturedVariables, sourceCode, features, numConstants);
    226 
    227     ASSERT(node->m_arena.last() == node);
    228     node->m_arena.removeLast();
    229     ASSERT(!node->m_arena.contains(node.get()));
    230 
    231     return node.release();
    232 }
    233 
    234 void FunctionBodyNode::setEndPosition(JSTextPosition position)
    235 {
    236     m_lastLine = position.line;
    237     m_endColumn = position.offset - position.lineStartOffset;
    238 }
    239 
    240241} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.