Reviewed by Sam Weinig.
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2007 00:01:13 +0000 (00:01 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Dec 2007 00:01:13 +0000 (00:01 +0000)
        Refactored parsing of global code: Removed the assumption that
        ProgramNode inherits from FunctionBodyNode from the parser.

        * kjs/Parser.cpp:
        (KJS::Parser::parseProgram):
        (KJS::Parser::parseFunctionBody):
        (KJS::Parser::parse):
        * kjs/Parser.h:
        (KJS::Parser::didFinishParsing):
        * kjs/function.cpp:
        * kjs/grammar.y:
        * kjs/nodes.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28540 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/Parser.cpp
JavaScriptCore/kjs/Parser.h
JavaScriptCore/kjs/function.cpp
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h

index c6a272b..0e01c8e 100644 (file)
@@ -1,5 +1,22 @@
 2007-12-07  Geoffrey Garen  <ggaren@apple.com>
 
+        Reviewed by Sam Weinig.
+        
+        Refactored parsing of global code: Removed the assumption that 
+        ProgramNode inherits from FunctionBodyNode from the parser.
+
+        * kjs/Parser.cpp:
+        (KJS::Parser::parseProgram):
+        (KJS::Parser::parseFunctionBody):
+        (KJS::Parser::parse):
+        * kjs/Parser.h:
+        (KJS::Parser::didFinishParsing):
+        * kjs/function.cpp:
+        * kjs/grammar.y:
+        * kjs/nodes.h:
+
+2007-12-07  Geoffrey Garen  <ggaren@apple.com>
+
         Build fix: added JSVariableObject.cpp to the .pri file.
 
         * JavaScriptCore.pri:
index 78ab73d..718cc8d 100644 (file)
@@ -44,7 +44,9 @@ PassRefPtr<ProgramNode> Parser::parseProgram(const UString& sourceURL, int start
     int* sourceId, int* errLine, UString* errMsg)
 {
     parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg);
-    return m_progNode.release();
+    if (!m_sourceElements)
+        return 0;
+    return new ProgramNode(m_sourceElements.release());
 }
 
 PassRefPtr<FunctionBodyNode> Parser::parseFunctionBody(const UString& sourceURL, int startingLineNumber,
@@ -52,14 +54,16 @@ PassRefPtr<FunctionBodyNode> Parser::parseFunctionBody(const UString& sourceURL,
     int* sourceId, int* errLine, UString* errMsg)
 {
     parse(sourceURL, startingLineNumber, code, length, sourceId, errLine, errMsg);
-    return m_progNode.release();
+    if (!m_sourceElements)
+        return 0;
+    return new FunctionBodyNode(m_sourceElements.release());
 }
 
 void Parser::parse(const UString& sourceURL, int startingLineNumber,
     const UChar* code, unsigned length,
     int* sourceId, int* errLine, UString* errMsg)
 {
-    ASSERT(!m_progNode);
+    ASSERT(!m_sourceElements);
 
     if (errLine)
         *errLine = -1;
@@ -84,15 +88,10 @@ void Parser::parse(const UString& sourceURL, int startingLineNumber,
             *errLine = lexer.lineNo();
         if (errMsg)
             *errMsg = "Parse error";
-        m_progNode = 0;
+        m_sourceElements.clear();
     }
 }
 
-void Parser::didFinishParsing(PassRefPtr<ProgramNode> progNode)
-{
-    m_progNode = progNode;
-}
-
 Parser& parser()
 {
     ASSERT(JSLock::currentThreadIsHoldingLock());
index db60b36..1eaef80 100644 (file)
@@ -28,6 +28,7 @@
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
 #include <wtf/RefPtr.h>
+#include "nodes.h"
 
 namespace KJS {
 
@@ -48,8 +49,11 @@ namespace KJS {
             int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
 
         int sourceId() { return m_sourceId; }
-        
-        void didFinishParsing(PassRefPtr<ProgramNode>);
+
+        void didFinishParsing(SourceElements* sourceElements)
+        {
+            m_sourceElements.set(sourceElements);
+        }
 
     private:
         friend Parser& parser();
@@ -60,7 +64,7 @@ namespace KJS {
             int* sourceId = 0, int* errLine = 0, UString* errMsg = 0);
 
         int m_sourceId;
-        RefPtr<ProgramNode> m_progNode;
+        OwnPtr<SourceElements> m_sourceElements;
     };
     
     Parser& parser(); // Returns the singleton JavaScript parser.
index 7a46c3a..d898e5a 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "ExecState.h"
 #include "JSGlobalObject.h"
-#include "JSVariableObject.h"
+#include "Parser.h"
 #include "PropertyNameArray.h"
 #include "debugger.h"
 #include "dtoa.h"
index 7d6bff4..e4b05dd 100644 (file)
@@ -878,8 +878,8 @@ FunctionBody:
 ;
 
 Program:
-    /* not in spec */                   { parser().didFinishParsing(new ProgramNode(new SourceElements)); }
-    | SourceElements                    { parser().didFinishParsing(new ProgramNode($1->release())); }
+    /* not in spec */                   { parser().didFinishParsing(new SourceElements); }
+    | SourceElements                    { parser().didFinishParsing($1->release()); }
 ;
 
 SourceElements:
index 1c89c3a..6be52d0 100644 (file)
@@ -3663,10 +3663,10 @@ static inline Completion statementListExecute(SourceElements& statements, ExecSt
 // ------------------------------ BlockNode ------------------------------------
 
 BlockNode::BlockNode(SourceElements* children)
+    : m_children(children)
 {
-    ASSERT(children);
+    ASSERT(m_children);
     m_mayHaveDeclarations = true; 
-    m_children.set(children);
 }
 
 void BlockNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
index aa10317..db52786 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef NODES_H_
 #define NODES_H_
 
-#include "Parser.h"
 #include "internal.h"
 #include "regexp.h"
 #include "SymbolTable.h"