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 c6a272bed702a8eb77168d9c49615e1465f9e85e..0e01c8e16cf0395232429203ef57600dc871cc0c 100644 (file)
@@ -1,3 +1,20 @@
+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.
index 78ab73d682262e72bd201ee8419a39df7cab2f24..718cc8d3b8a85a873f720ff7ac34301c7c85e329 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 db60b36b3d33a5ed44c6fca0162caf41fb0b3e0d..1eaef808b7a8952576dfca5a2eb4eaef6165d282 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 7a46c3ad90c4b70623c0ebda79c09f99471a0a0a..d898e5a85aedf36f84ac1e675c32a597b446bcaa 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 7d6bff47d9a508e0f82ab1d00df3b8769a791639..e4b05ddac681508a4fe9a9e8a8142c13999856ab 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 1c89c3a7bbd5230ff6e7f2b0eedcc8fc597a16e3..6be52d0d213b5eb154e12467a9a833048059d6bd 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 aa10317ae0010437bb18ec5f73ab3da4f9c0051c..db5278634d7d70cc66d24b324743a9ae7248ad29 100644 (file)
@@ -26,7 +26,6 @@
 #ifndef NODES_H_
 #define NODES_H_
 
-#include "Parser.h"
 #include "internal.h"
 #include "regexp.h"
 #include "SymbolTable.h"