Commit 60414e6b authored by darin's avatar darin

Reviewed by Maciej.

	- turned more recursion into iteration, and fixed some backwards stuff

        * kjs/grammar.y: Use the normal idiom for CaseClauses and FormalParameterList
	rather than using append().
        * kjs/grammar.cpp: Regenerated.

        * kjs/nodes.h: Change ClauseListNode and ParameterNode to use the normal idiom,
	and got rid of append methods. Also added friend declarations and calls to reverseList().
        * kjs/nodes.cpp:
        (StatListNode::ref): Iteration, not recursion.
        (StatListNode::deref): Iteration, not recursion.
        (StatListNode::execute): Iteration, not recursion.
        (StatListNode::processVarDecls): Iteration, not recursion.
        (CaseClauseNode::reverseList): Added.
        (ClauseListNode::ref): Iteration, not recursion.
        (ClauseListNode::deref): Iteration, not recursion.
        (ClauseListNode::processVarDecls): Iteration, not recursion.
        (CaseBlockNode::reverseLists): Added.
        (ParameterNode::ref): Iteration, not recursion.
        (ParameterNode::deref): Iteration, not recursion.
        (FuncDeclNode::reverseParameterList): Added.
        (FuncExprNode::reverseParameterList): Added.
        (SourceElementsNode::ref): Iteration, not recursion.
        (SourceElementsNode::deref): Iteration, not recursion.
        (SourceElementsNode::execute): Use variable name of n to match other functions.
        (SourceElementsNode::processFuncDecl): Ditto.
        (SourceElementsNode::processVarDecls): Ditto.

        * kjs/nodes2string.cpp:
        (SourceStream::operator<<): Used a switch statement for a bit of added clarity.
        (ElementNode::streamTo): Iteration, not recursion.
        (PropertyValueNode::streamTo): Iteration, not recursion.
        (ArgumentListNode::streamTo): Iteration, not recursion.
        (StatListNode::streamTo): Iteration, not recursion, and fixed order.
        (VarDeclListNode::streamTo): Iteration, not recursion.
        (ClauseListNode::streamTo): Used for statement to match other functions.
        (CaseBlockNode::streamTo): Used for statement to match other functions.
        (ParameterNode::streamTo): Iteration, not recursion.
        (SourceElementsNode::streamTo): Iteration, not recursion, and fixed order that has been
	backwards since I changed how this works in nodes.cpp.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@3313 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 767b3718
2003-01-12 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- turned more recursion into iteration, and fixed some backwards stuff
* kjs/grammar.y: Use the normal idiom for CaseClauses and FormalParameterList
rather than using append().
* kjs/grammar.cpp: Regenerated.
* kjs/nodes.h: Change ClauseListNode and ParameterNode to use the normal idiom,
and got rid of append methods. Also added friend declarations and calls to reverseList().
* kjs/nodes.cpp:
(StatListNode::ref): Iteration, not recursion.
(StatListNode::deref): Iteration, not recursion.
(StatListNode::execute): Iteration, not recursion.
(StatListNode::processVarDecls): Iteration, not recursion.
(CaseClauseNode::reverseList): Added.
(ClauseListNode::ref): Iteration, not recursion.
(ClauseListNode::deref): Iteration, not recursion.
(ClauseListNode::processVarDecls): Iteration, not recursion.
(CaseBlockNode::reverseLists): Added.
(ParameterNode::ref): Iteration, not recursion.
(ParameterNode::deref): Iteration, not recursion.
(FuncDeclNode::reverseParameterList): Added.
(FuncExprNode::reverseParameterList): Added.
(SourceElementsNode::ref): Iteration, not recursion.
(SourceElementsNode::deref): Iteration, not recursion.
(SourceElementsNode::execute): Use variable name of n to match other functions.
(SourceElementsNode::processFuncDecl): Ditto.
(SourceElementsNode::processVarDecls): Ditto.
* kjs/nodes2string.cpp:
(SourceStream::operator<<): Used a switch statement for a bit of added clarity.
(ElementNode::streamTo): Iteration, not recursion.
(PropertyValueNode::streamTo): Iteration, not recursion.
(ArgumentListNode::streamTo): Iteration, not recursion.
(StatListNode::streamTo): Iteration, not recursion, and fixed order.
(VarDeclListNode::streamTo): Iteration, not recursion.
(ClauseListNode::streamTo): Used for statement to match other functions.
(CaseBlockNode::streamTo): Used for statement to match other functions.
(ParameterNode::streamTo): Iteration, not recursion.
(SourceElementsNode::streamTo): Iteration, not recursion, and fixed order that has been
backwards since I changed how this works in nodes.cpp.
2003-01-11 Darin Adler <darin@apple.com>
Reviewed by John.
......
2003-01-12 Darin Adler <darin@apple.com>
Reviewed by Maciej.
- turned more recursion into iteration, and fixed some backwards stuff
* kjs/grammar.y: Use the normal idiom for CaseClauses and FormalParameterList
rather than using append().
* kjs/grammar.cpp: Regenerated.
* kjs/nodes.h: Change ClauseListNode and ParameterNode to use the normal idiom,
and got rid of append methods. Also added friend declarations and calls to reverseList().
* kjs/nodes.cpp:
(StatListNode::ref): Iteration, not recursion.
(StatListNode::deref): Iteration, not recursion.
(StatListNode::execute): Iteration, not recursion.
(StatListNode::processVarDecls): Iteration, not recursion.
(CaseClauseNode::reverseList): Added.
(ClauseListNode::ref): Iteration, not recursion.
(ClauseListNode::deref): Iteration, not recursion.
(ClauseListNode::processVarDecls): Iteration, not recursion.
(CaseBlockNode::reverseLists): Added.
(ParameterNode::ref): Iteration, not recursion.
(ParameterNode::deref): Iteration, not recursion.
(FuncDeclNode::reverseParameterList): Added.
(FuncExprNode::reverseParameterList): Added.
(SourceElementsNode::ref): Iteration, not recursion.
(SourceElementsNode::deref): Iteration, not recursion.
(SourceElementsNode::execute): Use variable name of n to match other functions.
(SourceElementsNode::processFuncDecl): Ditto.
(SourceElementsNode::processVarDecls): Ditto.
* kjs/nodes2string.cpp:
(SourceStream::operator<<): Used a switch statement for a bit of added clarity.
(ElementNode::streamTo): Iteration, not recursion.
(PropertyValueNode::streamTo): Iteration, not recursion.
(ArgumentListNode::streamTo): Iteration, not recursion.
(StatListNode::streamTo): Iteration, not recursion, and fixed order.
(VarDeclListNode::streamTo): Iteration, not recursion.
(ClauseListNode::streamTo): Used for statement to match other functions.
(CaseBlockNode::streamTo): Used for statement to match other functions.
(ParameterNode::streamTo): Iteration, not recursion.
(SourceElementsNode::streamTo): Iteration, not recursion, and fixed order that has been
backwards since I changed how this works in nodes.cpp.
2003-01-11 Darin Adler <darin@apple.com>
Reviewed by John.
......
......@@ -332,8 +332,8 @@ static const short yyrline[] = { 0,
483, 485, 489, 491, 498, 500, 504, 506, 514, 516,
520, 521, 527, 532, 537, 539, 543, 545, 548, 550,
553, 555, 558, 560, 563, 569, 573, 575, 576, 579,
583, 587, 590, 594, 596, 601, 603, 607, 610, 614,
617, 621, 623, 626, 628
583, 587, 590, 594, 596, 601, 603, 606, 609, 613,
616, 620, 622, 625, 627
};
#endif
......@@ -1899,7 +1899,7 @@ case 169:
break;}
case 170:
#line 550 "grammar.y"
{ yyval.clist = yyvsp[-1].clist->append(yyvsp[0].ccl); ;
{ yyval.clist = new ClauseListNode(yyvsp[-1].clist, yyvsp[0].ccl); ;
break;}
case 171:
#line 554 "grammar.y"
......@@ -1971,43 +1971,42 @@ case 186:
break;}
case 187:
#line 603 "grammar.y"
{ yyval.param = yyvsp[-2].param->append(*yyvsp[0].ident);
delete yyvsp[0].ident; ;
{ yyval.param = new ParameterNode(yyvsp[-2].param, *yyvsp[0].ident); delete yyvsp[0].ident; ;
break;}
case 188:
#line 608 "grammar.y"
#line 607 "grammar.y"
{ yyval.body = new FunctionBodyNode(0L);
DBG(yyval.body, yylsp[-1], yylsp[0]);;
break;}
case 189:
#line 610 "grammar.y"
#line 609 "grammar.y"
{ yyval.body = new FunctionBodyNode(yyvsp[-1].srcs);
DBG(yyval.body, yylsp[-2], yylsp[0]);;
break;}
case 190:
#line 615 "grammar.y"
#line 614 "grammar.y"
{ yyval.prog = new ProgramNode(0L);
Parser::progNode = yyval.prog; ;
break;}
case 191:
#line 617 "grammar.y"
#line 616 "grammar.y"
{ yyval.prog = new ProgramNode(yyvsp[0].srcs);
Parser::progNode = yyval.prog; ;
break;}
case 192:
#line 622 "grammar.y"
#line 621 "grammar.y"
{ yyval.srcs = new SourceElementsNode(yyvsp[0].stat); ;
break;}
case 193:
#line 623 "grammar.y"
#line 622 "grammar.y"
{ yyval.srcs = new SourceElementsNode(yyvsp[-1].srcs, yyvsp[0].stat); ;
break;}
case 194:
#line 627 "grammar.y"
#line 626 "grammar.y"
{ yyval.stat = yyvsp[0].stat; ;
break;}
case 195:
#line 628 "grammar.y"
#line 627 "grammar.y"
{ yyval.stat = yyvsp[0].func; ;
break;}
}
......@@ -2232,7 +2231,7 @@ yyerrhandle:
}
return 1;
}
#line 631 "grammar.y"
#line 630 "grammar.y"
int yyerror (const char *) /* Called by yyparse on error */
......
......@@ -547,7 +547,7 @@ CaseClausesOpt:
CaseClauses:
CaseClause { $$ = new ClauseListNode($1); }
| CaseClauses CaseClause { $$ = $1->append($2); }
| CaseClauses CaseClause { $$ = new ClauseListNode($1, $2); }
;
CaseClause:
......@@ -600,8 +600,7 @@ FunctionExpr:
FormalParameterList:
IDENT { $$ = new ParameterNode(*$1); delete $1; }
| FormalParameterList ',' IDENT { $$ = $1->append(*$3);
delete $3; }
| FormalParameterList ',' IDENT { $$ = new ParameterNode($1, *$3); delete $3; }
;
FunctionBody:
......
......@@ -1491,61 +1491,63 @@ Value CommaNode::evaluate(ExecState *exec)
void StatListNode::ref()
{
Node::ref();
if ( statement )
statement->ref();
if ( list )
list->ref();
for (StatListNode *n = this; n; n = n->list) {
n->Node::ref();
if (n->statement)
n->statement->ref();
}
}
bool StatListNode::deref()
{
if ( statement && statement->deref() )
delete statement;
if ( list && list->deref() )
delete list;
StatListNode *next;
for (StatListNode *n = this; n; n = next) {
next = n->list;
if (n->statement && n->statement->deref())
delete n->statement;
if (n != this && n->Node::deref())
delete n;
}
return Node::deref();
}
// ECMA 12.1
Completion StatListNode::execute(ExecState *exec)
{
if (!list) {
Completion c = statement->execute(exec);
Completion c = statement->execute(exec);
KJS_ABORTPOINT
if (exec->hadException()) {
Value ex = exec->exception();
exec->clearException();
return Completion(Throw, ex);
}
Value v = c.value();
for (StatListNode *n = list; n; n = n->list) {
Completion c2 = n->statement->execute(exec);
KJS_ABORTPOINT
if (c2.complType() != Normal)
return c2;
if (exec->hadException()) {
Value ex = exec->exception();
exec->clearException();
return Completion(Throw, ex);
}
else
return c;
}
Completion l = list->execute(exec);
KJS_ABORTPOINT
if (l.complType() != Normal)
return l;
Completion e = statement->execute(exec);
KJS_ABORTPOINT;
if (exec->hadException()) {
Value ex = exec->exception();
exec->clearException();
return Completion(Throw, ex);
if (c2.isValueCompletion())
v = c2.value();
c = c2;
}
Value v = e.isValueCompletion() ? e.value() : l.value();
return Completion(e.complType(), v, e.target() );
return Completion(c.complType(), v, c.target());
}
void StatListNode::processVarDecls(ExecState *exec)
{
statement->processVarDecls(exec);
if (list)
list->processVarDecls(exec);
for (StatListNode *n = this; n; n = n->list)
n->statement->processVarDecls(exec);
}
// ------------------------------ AssignExprNode -------------------------------
......@@ -2232,6 +2234,18 @@ void WithNode::processVarDecls(ExecState *exec)
// ------------------------------ CaseClauseNode -------------------------------
void CaseClauseNode::reverseList()
{
StatListNode *head = 0;
StatListNode *next;
for (StatListNode *n = list; n; n = next) {
next = n->list;
n->list = head;
head = n;
}
list = head;
}
void CaseClauseNode::ref()
{
Node::ref();
......@@ -2278,19 +2292,23 @@ void CaseClauseNode::processVarDecls(ExecState *exec)
void ClauseListNode::ref()
{
Node::ref();
if ( cl )
cl->ref();
if ( nx )
nx->ref();
for (ClauseListNode *n = this; n; n = n->nx) {
n->Node::ref();
if (n->cl)
n->cl->ref();
}
}
bool ClauseListNode::deref()
{
if ( cl && cl->deref() )
delete cl;
if ( nx && nx->deref() )
delete nx;
ClauseListNode *next;
for (ClauseListNode *n = this; n; n = next) {
next = n->nx;
if (n->cl && n->cl->deref())
delete n->cl;
if (n != this && n->Node::deref())
delete n;
}
return Node::deref();
}
......@@ -2302,26 +2320,35 @@ Value ClauseListNode::evaluate(ExecState */*exec*/)
}
// ECMA 12.11
ClauseListNode* ClauseListNode::append(CaseClauseNode *c)
{
ClauseListNode *l = this;
while (l->nx)
l = l->nx;
l->nx = new ClauseListNode(c);
return this;
}
void ClauseListNode::processVarDecls(ExecState *exec)
{
if (cl)
cl->processVarDecls(exec);
if (nx)
nx->processVarDecls(exec);
for (ClauseListNode *n = this; n; n = n->nx)
if (n->cl)
n->cl->processVarDecls(exec);
}
// ------------------------------ CaseBlockNode --------------------------------
void CaseBlockNode::reverseLists()
{
ClauseListNode *head = 0;
ClauseListNode *next;
for (ClauseListNode *n = list1; n; n = next) {
next = n->nx;
n->nx = head;
head = n;
}
list1 = head;
head = 0;
for (ClauseListNode *n = list2; n; n = next) {
next = n->nx;
n->nx = head;
head = n;
}
list2 = head;
}
void CaseBlockNode::ref()
{
Node::ref();
......@@ -2667,29 +2694,21 @@ void TryNode::processVarDecls(ExecState *exec)
void ParameterNode::ref()
{
Node::ref();
if ( next )
next->ref();
for (ParameterNode *n = this; n; n = n->next)
n->Node::ref();
}
bool ParameterNode::deref()
{
if ( next && next->deref() )
delete next;
ParameterNode *next;
for (ParameterNode *n = this; n; n = next) {
next = n->next;
if (n != this && n->Node::deref())
delete n;
}
return Node::deref();
}
ParameterNode* ParameterNode::append(const Identifier &i)
{
ParameterNode *p = this;
while (p->next)
p = p->next;
p->next = new ParameterNode(i);
return this;
}
// ECMA 13
Value ParameterNode::evaluate(ExecState */*exec*/)
{
......@@ -2713,6 +2732,18 @@ void FunctionBodyNode::processFuncDecl(ExecState *exec)
// ------------------------------ FuncDeclNode ---------------------------------
void FuncDeclNode::reverseParameterList()
{
ParameterNode *head = 0;
ParameterNode *next;
for (ParameterNode *n = param; n; n = next) {
next = n->next;
n->next = head;
head = n;
}
param = head;
}
void FuncDeclNode::ref()
{
Node::ref();
......@@ -2765,6 +2796,18 @@ void FuncDeclNode::processFuncDecl(ExecState *exec)
// ------------------------------ FuncExprNode ---------------------------------
void FuncExprNode::reverseParameterList()
{
ParameterNode *head = 0;
ParameterNode *next;
for (ParameterNode *n = param; n; n = next) {
next = n->next;
n->next = head;
head = n;
}
param = head;
}
void FuncExprNode::ref()
{
Node::ref();
......@@ -2804,19 +2847,23 @@ Value FuncExprNode::evaluate(ExecState *exec)
void SourceElementsNode::ref()
{
Node::ref();
if ( element )
element->ref();
if ( elements )
elements->ref();
for (SourceElementsNode *n = this; n; n = n->elements) {
n->Node::ref();
if (n->element)
n->element->ref();
}
}
bool SourceElementsNode::deref()
{
if ( element && element->deref() )
delete element;
if ( elements && elements->deref() )
delete elements;
SourceElementsNode *next;
for (SourceElementsNode *n = this; n; n = next) {
next = n->elements;
if (n->element && n->element->deref())
delete n->element;
if (n != this && n->Node::deref())
delete n;
}
return Node::deref();
}
......@@ -2830,8 +2877,8 @@ Completion SourceElementsNode::execute(ExecState *exec)
if (c1.complType() != Normal)
return c1;
for (SourceElementsNode *node = elements; node; node = node->elements) {
Completion c2 = node->element->execute(exec);
for (SourceElementsNode *n = elements; n; n = n->elements) {
Completion c2 = n->element->execute(exec);
if (c2.complType() != Normal)
return c2;
// The spec says to return c2 here, but it seems that mozilla returns c1 if
......@@ -2846,16 +2893,14 @@ Completion SourceElementsNode::execute(ExecState *exec)
// ECMA 14
void SourceElementsNode::processFuncDecl(ExecState *exec)
{
for (SourceElementsNode *node = this; node; node = node->elements) {
node->element->processFuncDecl(exec);
}
for (SourceElementsNode *n = this; n; n = n->elements)
n->element->processFuncDecl(exec);
}
void SourceElementsNode::processVarDecls(ExecState *exec)
{
for (SourceElementsNode *node = this; node; node = node->elements) {
node->element->processVarDecls(exec);
}
for (SourceElementsNode *n = this; n; n = n->elements)
n->element->processVarDecls(exec);
}
ProgramNode::ProgramNode(SourceElementsNode *s): FunctionBodyNode(s) {
......
......@@ -598,6 +598,7 @@ namespace KJS {
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
friend class CaseClauseNode;
StatementNode *statement;
StatListNode *list;
};
......@@ -802,7 +803,7 @@ namespace KJS {
class CaseClauseNode: public Node {
public:
CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { }
CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { reverseList(); }
virtual void ref();
virtual bool deref();
Value evaluate(ExecState *exec);
......@@ -810,6 +811,7 @@ namespace KJS {
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
void reverseList();
Node *expr;
StatListNode *list;
};
......@@ -817,15 +819,16 @@ namespace KJS {
class ClauseListNode : public Node {
public:
ClauseListNode(CaseClauseNode *c) : cl(c), nx(0L) { }
ClauseListNode(ClauseListNode *n, CaseClauseNode *c) : cl(c), nx(n) { }
virtual void ref();
virtual bool deref();
ClauseListNode* append(CaseClauseNode *c);
Value evaluate(ExecState *exec);
CaseClauseNode *clause() const { return cl; }
ClauseListNode *next() const { return nx; }
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
friend class CaseBlockNode;
CaseClauseNode *cl;
ClauseListNode *nx;
};
......@@ -833,7 +836,7 @@ namespace KJS {
class CaseBlockNode: public Node {
public:
CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2)
: list1(l1), def(d), list2(l2) { }
: list1(l1), def(d), list2(l2) { reverseLists(); }
virtual void ref();
virtual bool deref();
Value evaluate(ExecState *exec);
......@@ -841,6 +844,7 @@ namespace KJS {
virtual void processVarDecls(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
void reverseLists();
ClauseListNode *list1;
CaseClauseNode *def;
ClauseListNode *list2;
......@@ -927,7 +931,7 @@ namespace KJS {
class ParameterNode : public Node {
public:
ParameterNode(const Identifier &i) : id(i), next(0L) { }
ParameterNode *append(const Identifier &i);
ParameterNode(ParameterNode *list, const Identifier &i) : id(i), next(list) { }
virtual void ref();
virtual bool deref();
Value evaluate(ExecState *exec);
......@@ -935,6 +939,8 @@ namespace KJS {
ParameterNode *nextParam() { return next; }
virtual void streamTo(SourceStream &s) const;
private:
friend class FuncDeclNode;
friend class FuncExprNode;
Identifier id;
ParameterNode *next;
};
......@@ -949,7 +955,7 @@ namespace KJS {
class FuncDeclNode : public StatementNode {
public:
FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
: ident(i), param(p), body(b) { }
: ident(i), param(p), body(b) { reverseParameterList(); }
virtual void ref();
virtual bool deref();
Completion execute(ExecState */*exec*/)
......@@ -957,6 +963,7 @@ namespace KJS {
void processFuncDecl(ExecState *exec);
virtual void streamTo(SourceStream &s) const;
private:
void reverseParameterList();
Identifier ident;
ParameterNode *param;
FunctionBodyNode *body;
......@@ -965,12 +972,13 @@ namespace KJS {
class FuncExprNode : public Node {
public:
FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
: param(p), body(b) { }
: param(p), body(b) { reverseParameterList(); }
virtual void ref();
virtual bool deref();
Value evaluate(ExecState *exec);