Commit 8e8091f7 authored by darin's avatar darin

Reviewed by Don and Maciej.

	- follow-on to my fix for 3134693 that fixes one more case of recursion and simplifies further

        * kjs/grammar.y: Remove SourceElementNode and just use a StatementNode instead.
	Reverse SourceElements rule so the recursive rule comes first as in the original
	KJS code (avoids actual parser recursion).

        * kjs/grammar.cpp: Regenerated.
        * kjs/grammar.cpp.h: Regenerated.
        * kjs/grammar.h: Regenerated.

        * kjs/nodes.h: Make processFuncDecl a virtual function in StatementNode so that we can
	use a StatementNode instead of a SourceElementNode. Add a call to reverseList in BlockNode
	to correct the order of the linked list in SourceElementsNode, to replace the technique
	where we reversed it in the parser. Remove SourceElementNode class, and make the element in
	SourceElementsNode be a StatementNode instead.
        * kjs/nodes.cpp: Remove SourceElementNode code.
        (StatementNode::processFuncDecl): Added empty function.
        (BlockNode::reverseList): Added. Used to make the SourceElements list ordered correctly.
        * kjs/nodes2string.cpp: Remove SourceElementNode code.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3215 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5873ea08
2002-12-30 Darin Adler <darin@apple.com>
Reviewed by Don and Maciej.
- follow-on to my fix for 3134693 that fixes one more case of recursion and simplifies further
* kjs/grammar.y: Remove SourceElementNode and just use a StatementNode instead.
Reverse SourceElements rule so the recursive rule comes first as in the original
KJS code (avoids actual parser recursion).
* kjs/grammar.cpp: Regenerated.
* kjs/grammar.cpp.h: Regenerated.
* kjs/grammar.h: Regenerated.
* kjs/nodes.h: Make processFuncDecl a virtual function in StatementNode so that we can
use a StatementNode instead of a SourceElementNode. Add a call to reverseList in BlockNode
to correct the order of the linked list in SourceElementsNode, to replace the technique
where we reversed it in the parser. Remove SourceElementNode class, and make the element in
SourceElementsNode be a StatementNode instead.
* kjs/nodes.cpp: Remove SourceElementNode code.
(StatementNode::processFuncDecl): Added empty function.
(BlockNode::reverseList): Added. Used to make the SourceElements list ordered correctly.
* kjs/nodes2string.cpp: Remove SourceElementNode code.
=== Alexander-46 ===
2002-12-28 Darin Adler <darin@apple.com>
......
2002-12-30 Darin Adler <darin@apple.com>
Reviewed by Don and Maciej.
- follow-on to my fix for 3134693 that fixes one more case of recursion and simplifies further
* kjs/grammar.y: Remove SourceElementNode and just use a StatementNode instead.
Reverse SourceElements rule so the recursive rule comes first as in the original
KJS code (avoids actual parser recursion).
* kjs/grammar.cpp: Regenerated.
* kjs/grammar.cpp.h: Regenerated.
* kjs/grammar.h: Regenerated.
* kjs/nodes.h: Make processFuncDecl a virtual function in StatementNode so that we can
use a StatementNode instead of a SourceElementNode. Add a call to reverseList in BlockNode
to correct the order of the linked list in SourceElementsNode, to replace the technique
where we reversed it in the parser. Remove SourceElementNode class, and make the element in
SourceElementsNode be a StatementNode instead.
* kjs/nodes.cpp: Remove SourceElementNode code.
(StatementNode::processFuncDecl): Added empty function.
(BlockNode::reverseList): Added. Used to make the SourceElements list ordered correctly.
* kjs/nodes2string.cpp: Remove SourceElementNode code.
=== Alexander-46 ===
2002-12-28 Darin Adler <darin@apple.com>
......
This diff is collapsed.
......@@ -10,7 +10,6 @@ typedef union {
FuncDeclNode *func;
ProgramNode *prog;
AssignExprNode *init;
SourceElementNode *src;
SourceElementsNode *srcs;
StatListNode *slist;
ArgumentsNode *args;
......
......@@ -10,7 +10,6 @@ typedef union {
FuncDeclNode *func;
ProgramNode *prog;
AssignExprNode *init;
SourceElementNode *src;
SourceElementsNode *srcs;
StatListNode *slist;
ArgumentsNode *args;
......
......@@ -61,7 +61,6 @@ using namespace KJS;
FuncDeclNode *func;
ProgramNode *prog;
AssignExprNode *init;
SourceElementNode *src;
SourceElementsNode *srcs;
StatListNode *slist;
ArgumentsNode *args;
......@@ -136,12 +135,12 @@ using namespace KJS;
%type <stat> BreakStatement ReturnStatement WithStatement
%type <stat> SwitchStatement LabelledStatement
%type <stat> ThrowStatement TryStatement
%type <stat> SourceElement
%type <slist> StatementList
%type <init> Initializer
%type <func> FunctionDeclaration
%type <body> FunctionBody
%type <src> SourceElement
%type <srcs> SourceElements
%type <param> FormalParameterList
%type <op> AssignmentOperator
......@@ -621,12 +620,12 @@ Program:
SourceElements:
SourceElement { $$ = new SourceElementsNode($1); }
| SourceElement SourceElements { $$ = new SourceElementsNode($2, $1); }
| SourceElements SourceElement { $$ = new SourceElementsNode($1, $2); }
;
SourceElement:
Statement { $$ = new SourceElementNode($1); }
| FunctionDeclaration { $$ = new SourceElementNode($1); }
Statement { $$ = $1; }
| FunctionDeclaration { $$ = $1; }
;
%%
......
......@@ -160,6 +160,10 @@ bool StatementNode::abortStatement(ExecState *exec)
return false;
}
void StatementNode::processFuncDecl(ExecState *exec)
{
}
// ------------------------------ NullNode -------------------------------------
Value NullNode::evaluate(ExecState */*exec*/)
......@@ -1710,6 +1714,18 @@ void VarStatementNode::processVarDecls(ExecState *exec)
// ------------------------------ BlockNode ------------------------------------
void BlockNode::reverseList()
{
SourceElementsNode *head = 0;
SourceElementsNode *next;
for (SourceElementsNode *n = source; n; n = next) {
next = n->elements;
n->elements = head;
head = n;
}
source = head;
}
void BlockNode::ref()
{
Node::ref();
......@@ -2784,48 +2800,6 @@ Value FuncExprNode::evaluate(ExecState *exec)
return ret;
}
// ------------------------------ SourceElementNode ----------------------------
void SourceElementNode::ref()
{
Node::ref();
if ( statement )
statement->ref();
if ( function )
function->ref();
}
bool SourceElementNode::deref()
{
if ( statement && statement->deref() )
delete statement;
if ( function && function->deref() )
delete function;
return Node::deref();
}
// ECMA 14
Completion SourceElementNode::execute(ExecState *exec)
{
if (statement)
return statement->execute(exec);
return Completion(Normal);
}
// ECMA 14
void SourceElementNode::processFuncDecl(ExecState *exec)
{
if (function)
function->processFuncDecl(exec);
}
void SourceElementNode::processVarDecls(ExecState *exec)
{
if (statement)
statement->processVarDecls(exec);
}
// ------------------------------ SourceElementsNode ---------------------------
void SourceElementsNode::ref()
......
......@@ -123,6 +123,7 @@ namespace KJS {
bool abortStatement(ExecState *exec);
virtual Completion execute(ExecState *exec) = 0;
void pushLabel(const Identifier &id) { ls.push(id); }
virtual void processFuncDecl(ExecState *exec);
protected:
LabelStack ls;
private:
......@@ -655,13 +656,14 @@ namespace KJS {
class BlockNode : public StatementNode {
public:
BlockNode(SourceElementsNode *s) : source(s) {}
BlockNode(SourceElementsNode *s) : source(s) { reverseList(); }
virtual void ref();
virtual bool deref();
virtual Completion execute(ExecState *exec);
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
protected:
void reverseList();
SourceElementsNode *source;
};
......@@ -973,26 +975,11 @@ namespace KJS {
FunctionBodyNode *body;
};
class SourceElementNode : public StatementNode {
public:
SourceElementNode(StatementNode *s) : statement(s), function(0L) { }
SourceElementNode(FuncDeclNode *f) : statement(0L), function(f) { }
virtual void ref();
virtual bool deref();
Completion execute(ExecState *exec);
void processFuncDecl(ExecState *exec);
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
StatementNode *statement;
FuncDeclNode *function;
};
// A linked list of source element nodes
class SourceElementsNode : public StatementNode {
public:
SourceElementsNode(SourceElementNode *s1) { element = s1; elements = 0L; }
SourceElementsNode(SourceElementsNode *s1, SourceElementNode *s2)
SourceElementsNode(StatementNode *s1) { element = s1; elements = 0L; }
SourceElementsNode(SourceElementsNode *s1, StatementNode *s2)
{ elements = s1; element = s2; }
virtual void ref();
virtual bool deref();
......@@ -1001,7 +988,8 @@ namespace KJS {
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
SourceElementNode *element; // 'this' element
friend class BlockNode;
StatementNode *element; // 'this' element
SourceElementsNode *elements; // pointer to next
};
......
......@@ -595,14 +595,6 @@ void FuncExprNode::streamTo(SourceStream &s) const
<< ")" << body;
}
void SourceElementNode::streamTo(SourceStream &s) const
{
if (statement)
s << statement;
else
s << function;
}
void SourceElementsNode::streamTo(SourceStream &s) const
{
s << elements << element;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment