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


Ignore:
Timestamp:
Aug 11, 2005, 3:26:54 AM (20 years ago)
Author:
mjs
Message:

JavaScriptCore:

Reviewed by Geoff.

Refactor assignment grammar to avoid Reference type, and to later
be able to take advantage of writeable PropertySlots, when those
are added. I also fixed a minor bug, turning a function to a
string lost parentheses, I made sure they are printed at least
where semantically significant.

Test cases: see WebCore

  • kjs/grammar.y: Change grammar so that assignment expressions are parsed directly to nodes that know how to set the kind of location being assigned, instead of having a generic assign node that counts on evaluateReference.
  • kjs/lexer.cpp: Include grammar_types.h.
  • kjs/nodes.cpp: (BracketAccessorNode): Renamed from AccessorNode1 for clarity. (DotAccessorNode): Renamed from AccessorNode2 for clarity. (combineForAssignment): Inline function for doing the proper kind of operation for various update assignments like += or *=. (AssignResolveNode): Node that handles assignment to a bare identifier. (AssignDotNode): Node that handles assignments of the form EXPR . IDENT = EXPR (AssignBracketNode): EXPR [ IDENT ] = EXPR
  • kjs/nodes.h: Updated for declarations/renames of new classes.
  • kjs/nodes2string.cpp: (GroupNode::streamTo): Fixed to print parens around the expression. (BracketAccessorNode::streamTo): Renamed. (DotAccessorNode::streamTo): Renamed. (AssignResolveNode::streamTo): Added. (AssignBracketNode::streamTo): Added. (AssignDotNode::streamTo): Added. (streamAssignmentOperatorTo): helper function for the above
  • kjs/property_slot.h: (KJS::PropertySlot::isSet): Made this const.

WebCore:

Reviewed by Geoff.

Test cases added:

  • layout-tests/fast/js/assign.html: Added. Test case for assignment to make sure I didn't break anything.
  • layout-tests/fast/js/code-serialize-paren.html: Added, test case for a minor bug I fixed where parens were not getting serialized at all when turning a function into a string.
File:
1 edited

Legend:

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

    r10084 r10135  
    211211    virtual ValueImp *evaluate(ExecState *exec);
    212212    virtual Reference evaluateReference(ExecState *exec);
    213     virtual void streamTo(SourceStream &s) const { group->streamTo(s); }
     213    virtual void streamTo(SourceStream &s) const;
    214214  private:
    215215    Node *group;
     
    291291  };
    292292
    293   class AccessorNode1 : public Node {
    294   public:
    295     AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
     293  class BracketAccessorNode : public Node {
     294  public:
     295    BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    296296    virtual void ref();
    297297    virtual bool deref();
     
    304304  };
    305305
    306   class AccessorNode2 : public Node {
    307   public:
    308     AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }
     306  class DotAccessorNode : public Node {
     307  public:
     308    DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
    309309    virtual void ref();
    310310    virtual bool deref();
     
    581581  };
    582582
    583   class AssignNode : public Node {
    584   public:
    585     AssignNode(Node *l, Operator o, Node *e) : left(l), oper(o), expr(e) {}
    586     virtual void ref();
    587     virtual bool deref();
    588     ValueImp *evaluate(ExecState *exec);
    589     virtual void streamTo(SourceStream &s) const;
    590   private:
    591     Node *left;
    592     Operator oper;
    593     Node *expr;
     583  class AssignResolveNode : public Node {
     584  public:
     585    AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
     586      : m_ident(ident), m_oper(oper), m_right(right) {}
     587    virtual void ref();
     588    virtual bool deref();
     589    ValueImp *evaluate(ExecState *exec);
     590    virtual void streamTo(SourceStream &s) const;
     591  protected:
     592    Identifier m_ident;
     593    Operator m_oper;
     594    Node *m_right;
     595  };
     596
     597  class AssignBracketNode : public Node {
     598  public:
     599    AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
     600      : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
     601    virtual void ref();
     602    virtual bool deref();
     603    ValueImp *evaluate(ExecState *exec);
     604    virtual void streamTo(SourceStream &s) const;
     605  protected:
     606    Node *m_base;
     607    Node *m_subscript;
     608    Operator m_oper;
     609    Node *m_right;
     610  };
     611
     612  class AssignDotNode : public Node {
     613  public:
     614    AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
     615      : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
     616    virtual void ref();
     617    virtual bool deref();
     618    ValueImp *evaluate(ExecState *exec);
     619    virtual void streamTo(SourceStream &s) const;
     620  protected:
     621    Node *m_base;
     622    Identifier m_ident;
     623    Operator m_oper;
     624    Node *m_right;
    594625  };
    595626
Note: See TracChangeset for help on using the changeset viewer.