Changeset 3313 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Jan 13, 2003, 7:49:23 AM (22 years ago)
Author:
darin
Message:

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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r3306 r3313  
    14921492void StatListNode::ref()
    14931493{
    1494   Node::ref();
    1495   if ( statement )
    1496     statement->ref();
    1497   if ( list )
    1498     list->ref();
     1494  for (StatListNode *n = this; n; n = n->list) {
     1495    n->Node::ref();
     1496    if (n->statement)
     1497      n->statement->ref();
     1498  }
    14991499}
    15001500
    15011501bool StatListNode::deref()
    15021502{
    1503   if ( statement && statement->deref() )
    1504     delete statement;
    1505   if ( list && list->deref() )
    1506     delete list;
     1503  StatListNode *next;
     1504  for (StatListNode *n = this; n; n = next) {
     1505    next = n->list;
     1506    if (n->statement && n->statement->deref())
     1507      delete n->statement;
     1508    if (n != this && n->Node::deref())
     1509      delete n;
     1510  }
    15071511  return Node::deref();
    15081512}
     
    15111515Completion StatListNode::execute(ExecState *exec)
    15121516{
    1513   if (!list) {
    1514     Completion c = statement->execute(exec);
     1517  Completion c = statement->execute(exec);
     1518  KJS_ABORTPOINT
     1519  if (exec->hadException()) {
     1520    Value ex = exec->exception();
     1521    exec->clearException();
     1522    return Completion(Throw, ex);
     1523  }
     1524 
     1525  Value v = c.value();
     1526 
     1527  for (StatListNode *n = list; n; n = n->list) {
     1528    Completion c2 = n->statement->execute(exec);
    15151529    KJS_ABORTPOINT
     1530    if (c2.complType() != Normal)
     1531      return c2;
     1532
    15161533    if (exec->hadException()) {
    15171534      Value ex = exec->exception();
     
    15191536      return Completion(Throw, ex);
    15201537    }
    1521     else
    1522       return c;
    1523   }
    1524 
    1525   Completion l = list->execute(exec);
    1526   KJS_ABORTPOINT
    1527   if (l.complType() != Normal)
    1528     return l;
    1529   Completion e = statement->execute(exec);
    1530   KJS_ABORTPOINT;
    1531 
    1532   if (exec->hadException()) {
    1533     Value ex = exec->exception();
    1534     exec->clearException();
    1535     return Completion(Throw, ex);
    1536   }
    1537 
    1538   Value v = e.isValueCompletion() ? e.value() : l.value();
    1539 
    1540   return Completion(e.complType(), v, e.target() );
     1538
     1539    if (c2.isValueCompletion())
     1540      v = c2.value();
     1541    c = c2;
     1542  }
     1543
     1544  return Completion(c.complType(), v, c.target());
    15411545}
    15421546
    15431547void StatListNode::processVarDecls(ExecState *exec)
    15441548{
    1545   statement->processVarDecls(exec);
    1546 
    1547   if (list)
    1548     list->processVarDecls(exec);
     1549  for (StatListNode *n = this; n; n = n->list)
     1550    n->statement->processVarDecls(exec);
    15491551}
    15501552
     
    22332235// ------------------------------ CaseClauseNode -------------------------------
    22342236
     2237void CaseClauseNode::reverseList()
     2238{
     2239  StatListNode *head = 0;
     2240  StatListNode *next;
     2241  for (StatListNode *n = list; n; n = next) {
     2242    next = n->list;
     2243    n->list = head;
     2244    head = n;
     2245  }
     2246  list = head;
     2247}
     2248
    22352249void CaseClauseNode::ref()
    22362250{
     
    22792293void ClauseListNode::ref()
    22802294{
    2281   Node::ref();
    2282   if ( cl )
    2283     cl->ref();
    2284   if ( nx )
    2285     nx->ref();
     2295  for (ClauseListNode *n = this; n; n = n->nx) {
     2296    n->Node::ref();
     2297    if (n->cl)
     2298      n->cl->ref();
     2299  }
    22862300}
    22872301
    22882302bool ClauseListNode::deref()
    22892303{
    2290   if ( cl && cl->deref() )
    2291     delete cl;
    2292   if ( nx && nx->deref() )
    2293     delete nx;
     2304  ClauseListNode *next;
     2305  for (ClauseListNode *n = this; n; n = next) {
     2306    next = n->nx;
     2307    if (n->cl && n->cl->deref())
     2308      delete n->cl;
     2309    if (n != this && n->Node::deref())
     2310      delete n;
     2311  }
    22942312  return Node::deref();
    22952313}
     
    23032321
    23042322// ECMA 12.11
    2305 ClauseListNode* ClauseListNode::append(CaseClauseNode *c)
    2306 {
    2307   ClauseListNode *l = this;
    2308   while (l->nx)
    2309     l = l->nx;
    2310   l->nx = new ClauseListNode(c);
    2311 
    2312   return this;
    2313 }
    2314 
    23152323void ClauseListNode::processVarDecls(ExecState *exec)
    23162324{
    2317   if (cl)
    2318     cl->processVarDecls(exec);
    2319   if (nx)
    2320     nx->processVarDecls(exec);
     2325  for (ClauseListNode *n = this; n; n = n->nx)
     2326    if (n->cl)
     2327      n->cl->processVarDecls(exec);
    23212328}
    23222329
    23232330// ------------------------------ CaseBlockNode --------------------------------
     2331
     2332void CaseBlockNode::reverseLists()
     2333{
     2334  ClauseListNode *head = 0;
     2335  ClauseListNode *next;
     2336  for (ClauseListNode *n = list1; n; n = next) {
     2337    next = n->nx;
     2338    n->nx = head;
     2339    head = n;
     2340  }
     2341  list1 = head;
     2342 
     2343  head = 0;
     2344  for (ClauseListNode *n = list2; n; n = next) {
     2345    next = n->nx;
     2346    n->nx = head;
     2347    head = n;
     2348  }
     2349  list2 = head;
     2350}
    23242351
    23252352void CaseBlockNode::ref()
     
    26682695void ParameterNode::ref()
    26692696{
    2670   Node::ref();
    2671   if ( next )
    2672     next->ref();
     2697  for (ParameterNode *n = this; n; n = n->next)
     2698    n->Node::ref();
    26732699}
    26742700
    26752701bool ParameterNode::deref()
    26762702{
    2677   if ( next && next->deref() )
    2678     delete next;
    2679   return Node::deref();
    2680 }
    2681 
    2682 ParameterNode* ParameterNode::append(const Identifier &i)
    2683 {
    2684   ParameterNode *p = this;
    2685   while (p->next)
    2686     p = p->next;
    2687 
    2688   p->next = new ParameterNode(i);
    2689 
    2690   return this;
     2703  ParameterNode *next;
     2704  for (ParameterNode *n = this; n; n = next) {
     2705    next = n->next;
     2706    if (n != this && n->Node::deref())
     2707      delete n;
     2708  }
     2709  return Node::deref();
    26912710}
    26922711
     
    27132732
    27142733// ------------------------------ FuncDeclNode ---------------------------------
     2734
     2735void FuncDeclNode::reverseParameterList()
     2736{
     2737  ParameterNode *head = 0;
     2738  ParameterNode *next;
     2739  for (ParameterNode *n = param; n; n = next) {
     2740    next = n->next;
     2741    n->next = head;
     2742    head = n;
     2743  }
     2744  param = head;
     2745}
    27152746
    27162747void FuncDeclNode::ref()
     
    27662797// ------------------------------ FuncExprNode ---------------------------------
    27672798
     2799void FuncExprNode::reverseParameterList()
     2800{
     2801  ParameterNode *head = 0;
     2802  ParameterNode *next;
     2803  for (ParameterNode *n = param; n; n = next) {
     2804    next = n->next;
     2805    n->next = head;
     2806    head = n;
     2807  }
     2808  param = head;
     2809}
     2810
    27682811void FuncExprNode::ref()
    27692812{
     
    28052848void SourceElementsNode::ref()
    28062849{
    2807   Node::ref();
    2808   if ( element )
    2809     element->ref();
    2810   if ( elements )
    2811     elements->ref();
     2850  for (SourceElementsNode *n = this; n; n = n->elements) {
     2851    n->Node::ref();
     2852    if (n->element)
     2853      n->element->ref();
     2854  }
    28122855}
    28132856
    28142857bool SourceElementsNode::deref()
    28152858{
    2816   if ( element && element->deref() )
    2817     delete element;
    2818   if ( elements && elements->deref() )
    2819     delete elements;
     2859  SourceElementsNode *next;
     2860  for (SourceElementsNode *n = this; n; n = next) {
     2861    next = n->elements;
     2862    if (n->element && n->element->deref())
     2863      delete n->element;
     2864    if (n != this && n->Node::deref())
     2865      delete n;
     2866  }
    28202867  return Node::deref();
    28212868}
     
    28312878    return c1;
    28322879 
    2833   for (SourceElementsNode *node = elements; node; node = node->elements) {
    2834     Completion c2 = node->element->execute(exec);
     2880  for (SourceElementsNode *n = elements; n; n = n->elements) {
     2881    Completion c2 = n->element->execute(exec);
    28352882    if (c2.complType() != Normal)
    28362883      return c2;
     
    28472894void SourceElementsNode::processFuncDecl(ExecState *exec)
    28482895{
    2849   for (SourceElementsNode *node = this; node; node = node->elements) {
    2850     node->element->processFuncDecl(exec);
    2851   }
     2896  for (SourceElementsNode *n = this; n; n = n->elements)
     2897    n->element->processFuncDecl(exec);
    28522898}
    28532899
    28542900void SourceElementsNode::processVarDecls(ExecState *exec)
    28552901{
    2856   for (SourceElementsNode *node = this; node; node = node->elements) {
    2857     node->element->processVarDecls(exec);
    2858   }
     2902  for (SourceElementsNode *n = this; n; n = n->elements)
     2903    n->element->processVarDecls(exec);
    28592904}
    28602905
Note: See TracChangeset for help on using the changeset viewer.