Changeset 5356 in webkit for trunk/JavaScriptCore/kjs/nodes.h


Ignore:
Timestamp:
Nov 2, 2003, 2:51:46 PM (22 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • changed list manipulation to use Harri Porten's idea of a circular linked list that is built from head to tail rather than building the list backwards and reversing the list when done
  • kjs/grammar.y: Handle CatchNode and FinallyNode in a type-safe way. Change many places that passed 0L to pass nothing at all, or to pass 0.
  • kjs/nodes.h: (KJS::ElementNode::ElementNode): Build a circular list instead of a 0-terminated backwards list. (KJS::ArrayNode::ArrayNode): Break the circular list instead of reversing the list. (KJS::PropertyValueNode::PropertyValueNode): Moved before ObjectLiteralNode so the inline code in ObjectLiteralNode works. Build a circular list instead of a 0-terminated backwards list. Made the case for the first node separate so we don't need a nil check. (KJS::ObjectLiteralNode::ObjectLiteralNode): Break the circular list instead of reversing the list. (KJS::ArgumentListNode::ArgumentListNode): Build a circular list instead of a 0-terminated backwards list. Also, made the constructors inline (moved here from .cpp file). (KJS::ArgumentsNode::ArgumentsNode): Break the circular list instead of reversing the list. (KJS::NewExprNode::NewExprNode): Changed a 0L to 0. (KJS::StatListNode::StatListNode): Make this constructor no longer inline (moved into .cpp file). The one in the .cpp file builds a circular list instead of a 0-terminated backwards list. (KJS::VarDeclListNode::VarDeclListNode): Build a circular list instead of a 0-terminated backwards list. (KJS::VarStatementNode::VarStatementNode): Break the circular list instead of reversing the list. (KJS::BlockNode::BlockNode): Make this constructor no longer inline (moved into .cpp file). The one in the .cpp file breaks the list instead of reversing it. (KJS::ForNode::ForNode): Break the circular list instead of reversing the list. (KJS::CaseClauseNode::CaseClauseNode): Break the circular list instead of reversing the list. (KJS::ClauseListNode::ClauseListNode): Build a circular list instead of a 0-terminated backwards list. (KJS::CaseBlockNode::CaseBlockNode): Make this constructor no longer inline (moved into .cpp file). The one in the .cpp file breaks the list instead of reversing it. (KJS::TryNode::TryNode): Changed constructor to take typed parameters for the catch and finally nodes rather than just Node. (KJS::ParameterNode::ParameterNode): Build a circular list instead of a 0-terminated backwards list. (KJS::FuncDeclNode::FuncDeclNode): Break the circular list instead of reversing the list. (KJS::FuncExprNode::FuncExprNode): Break the circular list instead of reversing the list.
  • kjs/nodes.cpp: (StatListNode::StatListNode): Moved this constructor here, no longer inline. Did the "break circular list" thing instead of the "reverse list" thing. Added setLoc calls to match KJS in the KDE tree; since we don't currently use the JavaScript debugging support, it's unclear whether there's any benefit, but later we might be using it and it's good to be as close as possible. (BlockNode::BlockNode): Moved this constructor here, no longer inline. Did the "break circular list" thing instead of the "reverse list" thing. Added setLoc calls. (CaseBlockNode::CaseBlockNode): Moved this constructor here, no longer inline. Did the "break circular list" thing instead of the "reverse list" thing. (SourceElementsNode::SourceElementsNode): Moved this constructor here, no longer inline. Did the "break circular list" thing instead of the "reverse list" thing. Added setLoc calls.
  • kjs/grammar.cpp: Regenerated.
  • kjs/grammar.cpp.h: Regenerated.
  • kjs/grammar.h: Regenerated.
File:
1 edited

Legend:

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

    r5209 r5356  
    210210  class ElementNode : public Node {
    211211  public:
    212     ElementNode(int e, Node *n) : list(0L), elision(e), node(n) { }
     212    // list pointer is tail of a circular list, cracked in the ArrayNode ctor
     213    ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }
    213214    ElementNode(ElementNode *l, int e, Node *n)
    214       : list(l), elision(e), node(n) { }
     215      : list(l->list), elision(e), node(n) { l->list = this; }
    215216    virtual void ref();
    216217    virtual bool deref();
     
    226227  class ArrayNode : public Node {
    227228  public:
    228     ArrayNode(int e) : element(0L), elision(e), opt(true) { }
     229    ArrayNode(int e) : element(0), elision(e), opt(true) { }
    229230    ArrayNode(ElementNode *ele)
    230       : element(ele), elision(0), opt(false) { reverseElementList(); }
     231      : element(ele->list), elision(0), opt(false) { ele->list = 0; }
    231232    ArrayNode(int eli, ElementNode *ele)
    232       : element(ele), elision(eli), opt(true) { reverseElementList(); }
    233     virtual void ref();
    234     virtual bool deref();
    235     Value evaluate(ExecState *exec);
    236     virtual void streamTo(SourceStream &s) const;
    237   private:
    238     void reverseElementList();
     233      : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
     234    virtual void ref();
     235    virtual bool deref();
     236    Value evaluate(ExecState *exec);
     237    virtual void streamTo(SourceStream &s) const;
     238  private:
    239239    ElementNode *element;
    240240    int elision;
     
    242242  };
    243243
    244   class ObjectLiteralNode : public Node {
    245   public:
    246     ObjectLiteralNode(PropertyValueNode *l) : list(l) { reverseList(); }
    247     virtual void ref();
    248     virtual bool deref();
    249     Value evaluate(ExecState *exec);
    250     virtual void streamTo(SourceStream &s) const;
    251   private:
    252     void reverseList();
    253     PropertyValueNode *list;
    254   };
    255 
    256244  class PropertyValueNode : public Node {
    257245  public:
    258     PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l = 0L)
    259       : name(n), assign(a), list(l) { }
     246    // list pointer is tail of a circular list, cracked in the ObjectLiteralNode ctor
     247    PropertyValueNode(PropertyNode *n, Node *a)
     248      : name(n), assign(a), list(this) { }
     249    PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
     250      : name(n), assign(a), list(l->list) { l->list = this; }
    260251    virtual void ref();
    261252    virtual bool deref();
     
    269260  };
    270261
     262  class ObjectLiteralNode : public Node {
     263  public:
     264    ObjectLiteralNode() : list(0) { }
     265    ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
     266    virtual void ref();
     267    virtual bool deref();
     268    Value evaluate(ExecState *exec);
     269    virtual void streamTo(SourceStream &s) const;
     270  private:
     271    PropertyValueNode *list;
     272  };
     273
    271274  class PropertyNode : public Node {
    272275  public:
     
    308311  class ArgumentListNode : public Node {
    309312  public:
    310     ArgumentListNode(Node *e);
    311     ArgumentListNode(ArgumentListNode *l, Node *e);
     313    // list pointer is tail of a circular list, cracked in the ArgumentsNode ctor
     314    ArgumentListNode(Node *e) : list(this), expr(e) { }
     315    ArgumentListNode(ArgumentListNode *l, Node *e)
     316      : list(l->list), expr(e) { l->list = this; }
    312317    virtual void ref();
    313318    virtual bool deref();
     
    323328  class ArgumentsNode : public Node {
    324329  public:
    325     ArgumentsNode(ArgumentListNode *l) : list(l) { reverseList(); }
     330    ArgumentsNode() : list(0) { }
     331    ArgumentsNode(ArgumentListNode *l)
     332      : list(l->list) { l->list = 0; }
    326333    virtual void ref();
    327334    virtual bool deref();
     
    330337    virtual void streamTo(SourceStream &s) const;
    331338  private:
    332     void reverseList();
    333339    ArgumentListNode *list;
    334340  };
     
    336342  class NewExprNode : public Node {
    337343  public:
    338     NewExprNode(Node *e) : expr(e), args(0L) {}
     344    NewExprNode(Node *e) : expr(e), args(0) {}
    339345    NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    340346    virtual void ref();
     
    593599  class StatListNode : public StatementNode {
    594600  public:
    595     StatListNode(StatementNode *s) : statement(s), list(0L) { }
    596     StatListNode(StatListNode *l, StatementNode *s) : statement(s), list(l) { }
     601    // list pointer is tail of a circular list, cracked in the CaseClauseNode ctor
     602    StatListNode(StatementNode *s);
     603    StatListNode(StatListNode *l, StatementNode *s);
    597604    virtual void ref();
    598605    virtual bool deref();
     
    632639  class VarDeclListNode : public Node {
    633640  public:
    634     VarDeclListNode(VarDeclNode *v) : list(0L), var(v) {}
    635     VarDeclListNode(VarDeclListNode *l, VarDeclNode *v) : list(l), var(v) {}
     641    // list pointer is tail of a circular list, cracked in the ForNode/VarStatementNode ctor
     642    VarDeclListNode(VarDeclNode *v) : list(this), var(v) {}
     643    VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
     644      : list(l->list), var(v) { l->list = this; }
    636645    virtual void ref();
    637646    virtual bool deref();
     
    648657  class VarStatementNode : public StatementNode {
    649658  public:
    650     VarStatementNode(VarDeclListNode *l) : list(l) { reverseList(); }
    651     virtual void ref();
    652     virtual bool deref();
    653     virtual Completion execute(ExecState *exec);
    654     virtual void processVarDecls(ExecState *exec);
    655     virtual void streamTo(SourceStream &s) const;
    656   private:
    657     void reverseList();
     659    VarStatementNode(VarDeclListNode *l)
     660      : list(l->list) { l->list = 0; }
     661    virtual void ref();
     662    virtual bool deref();
     663    virtual Completion execute(ExecState *exec);
     664    virtual void processVarDecls(ExecState *exec);
     665    virtual void streamTo(SourceStream &s) const;
     666  private:
    658667    VarDeclListNode *list;
    659668  };
     
    661670  class BlockNode : public StatementNode {
    662671  public:
    663     BlockNode(SourceElementsNode *s) : source(s) { reverseList(); }
     672    BlockNode(SourceElementsNode *s);
    664673    virtual void ref();
    665674    virtual bool deref();
     
    668677    virtual void streamTo(SourceStream &s) const;
    669678  protected:
    670     void reverseList();
    671679    SourceElementsNode *source;
    672680  };
     
    735743      expr1(e1), expr2(e2), expr3(e3), statement(s) {}
    736744    ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
    737       expr1(reverseList(e1)), expr2(e2), expr3(e3), statement(s) {}
    738     virtual void ref();
    739     virtual bool deref();
    740     virtual Completion execute(ExecState *exec);
    741     virtual void processVarDecls(ExecState *exec);
    742     virtual void streamTo(SourceStream &s) const;
    743   private:
    744     static VarDeclListNode *reverseList(VarDeclListNode *);
     745      expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
     746    virtual void ref();
     747    virtual bool deref();
     748    virtual Completion execute(ExecState *exec);
     749    virtual void processVarDecls(ExecState *exec);
     750    virtual void streamTo(SourceStream &s) const;
     751  private:
    745752    Node *expr1, *expr2, *expr3;
    746753    StatementNode *statement;
     
    808815  };
    809816
    810   class CaseClauseNode: public Node {
    811   public:
    812     CaseClauseNode(Node *e, StatListNode *l) : expr(e), list(l) { reverseList(); }
     817  class CaseClauseNode : public Node {
     818  public:
     819    CaseClauseNode(Node *e) : expr(e), list(0) { }
     820    CaseClauseNode(Node *e, StatListNode *l)
     821      : expr(e), list(l->list) { l->list = 0; }
    813822    virtual void ref();
    814823    virtual bool deref();
     
    818827    virtual void streamTo(SourceStream &s) const;
    819828  private:
    820     void reverseList();
    821829    Node *expr;
    822830    StatListNode *list;
     
    825833  class ClauseListNode : public Node {
    826834  public:
    827     ClauseListNode(CaseClauseNode *c) : cl(c), nx(0L) { }
    828     ClauseListNode(ClauseListNode *n, CaseClauseNode *c) : cl(c), nx(n) { }
     835    // list pointer is tail of a circular list, cracked in the CaseBlockNode ctor
     836    ClauseListNode(CaseClauseNode *c) : cl(c), nx(this) { }
     837    ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
     838      : cl(c), nx(n->nx) { n->nx = this; }
    829839    virtual void ref();
    830840    virtual bool deref();
     
    840850  };
    841851
    842   class CaseBlockNode: public Node {
    843   public:
    844     CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2)
    845       : list1(l1), def(d), list2(l2) { reverseLists(); }
     852  class CaseBlockNode : public Node {
     853  public:
     854    CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
    846855    virtual void ref();
    847856    virtual bool deref();
     
    851860    virtual void streamTo(SourceStream &s) const;
    852861  private:
    853     void reverseLists();
    854862    ClauseListNode *list1;
    855863    CaseClauseNode *def;
     
    922930  class TryNode : public StatementNode {
    923931  public:
    924     TryNode(StatementNode *b, Node *c = 0L, Node *f = 0L)
    925       : block(b), _catch((CatchNode*)c), _final((FinallyNode*)f) {}
     932    TryNode(StatementNode *b, CatchNode *c)
     933      : block(b), _catch(c), _final(0) {}
     934    TryNode(StatementNode *b, FinallyNode *f)
     935      : block(b), _catch(0), _final(f) {}
     936    TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
     937      : block(b), _catch(c), _final(f) {}
    926938    virtual void ref();
    927939    virtual bool deref();
     
    937949  class ParameterNode : public Node {
    938950  public:
    939     ParameterNode(const Identifier &i) : id(i), next(0L) { }
    940     ParameterNode(ParameterNode *list, const Identifier &i) : id(i), next(list) { }
     951    // list pointer is tail of a circular list, cracked in the FuncDeclNode/FuncExprNode ctor
     952    ParameterNode(const Identifier &i) : id(i), next(this) { }
     953    ParameterNode(ParameterNode *list, const Identifier &i)
     954      : id(i), next(list->next) { list->next = this; }
    941955    virtual void ref();
    942956    virtual bool deref();
     
    961975  class FuncDeclNode : public StatementNode {
    962976  public:
     977    FuncDeclNode(const Identifier &i, FunctionBodyNode *b)
     978      : ident(i), param(0), body(b) { }
    963979    FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
    964       : ident(i), param(p), body(b) { reverseParameterList(); }
     980      : ident(i), param(p->next), body(b) { p->next = 0; }
    965981    virtual void ref();
    966982    virtual bool deref();
     
    970986    virtual void streamTo(SourceStream &s) const;
    971987  private:
    972     void reverseParameterList();
    973988    Identifier ident;
    974989    ParameterNode *param;
     
    978993  class FuncExprNode : public Node {
    979994  public:
     995    FuncExprNode(FunctionBodyNode *b) : param(0), body(b) { }
    980996    FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
    981         : param(p), body(b) { reverseParameterList(); }
    982     virtual void ref();
    983     virtual bool deref();
    984     Value evaluate(ExecState *exec);
    985     virtual void streamTo(SourceStream &s) const;
    986   private:
    987     void reverseParameterList();
     997      : param(p->next), body(b) { p->next = 0; }
     998    virtual void ref();
     999    virtual bool deref();
     1000    Value evaluate(ExecState *exec);
     1001    virtual void streamTo(SourceStream &s) const;
     1002  private:
    9881003    ParameterNode *param;
    9891004    FunctionBodyNode *body;
     
    9931008  class SourceElementsNode : public StatementNode {
    9941009  public:
    995     SourceElementsNode(StatementNode *s1) { element = s1; elements = 0L; }
    996     SourceElementsNode(SourceElementsNode *s1, StatementNode *s2)
    997       { elements = s1; element = s2; }
     1010    // list pointer is tail of a circular list, cracked in the BlockNode (or subclass) ctor
     1011    SourceElementsNode(StatementNode *s1);
     1012    SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
    9981013    virtual void ref();
    9991014    virtual bool deref();
Note: See TracChangeset for help on using the changeset viewer.