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


Ignore:
Timestamp:
Aug 26, 2005, 4:42:16 PM (20 years ago)
Author:
mjs
Message:

Reviewed by John.

  • fixed <rdar://problem/4232452> many many leaks in kjsyyparse on some well-formed JavaScript (can repro on sony.com, webkit tests)

Fixed by changing the refcounting scheme for nodes. Instead of each node implementing a custom ref and
deref for all its children (and being responsible for deleting them), nodes use a smart pointer to
hold their children, and smart pointers are used outside the node tree as well. This change mostly
removes code.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/function.cpp: (KJS::DeclaredFunctionImp::DeclaredFunctionImp): (KJS::GlobalFuncImp::callAsFunction):
  • kjs/function.h:
  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/grammar.y:
  • kjs/internal.cpp: (KJS::Parser::parse): (KJS::Parser::accept): (KJS::InterpreterImp::checkSyntax): (KJS::InterpreterImp::evaluate):
  • kjs/internal.h:
  • kjs/nodes.cpp: (Node::Node): (Node::~Node): (ElementNode::evaluate): (PropertyValueNode::evaluate): (ArgumentListNode::evaluateList): (NewExprNode::evaluate): (FunctionCallValueNode::evaluate): (FunctionCallBracketNode::evaluate): (FunctionCallDotNode::evaluate): (RelationalNode::evaluate): (StatListNode::execute): (StatListNode::processVarDecls): (VarDeclListNode::evaluate): (VarDeclListNode::processVarDecls): (ForInNode::ForInNode): (ClauseListNode::processVarDecls): (CaseBlockNode::evalBlock): (FuncDeclNode::processFuncDecl): (FuncExprNode::evaluate): (SourceElementsNode::execute): (SourceElementsNode::processFuncDecl): (SourceElementsNode::processVarDecls):
  • kjs/nodes.h: (KJS::Node::ref): (KJS::Node::deref): (KJS::NumberNode::NumberNode): (KJS::GroupNode::GroupNode): (KJS::ElementNode::ElementNode): (KJS::ArrayNode::ArrayNode): (KJS::PropertyValueNode::PropertyValueNode): (KJS::ObjectLiteralNode::ObjectLiteralNode): (KJS::BracketAccessorNode::BracketAccessorNode): (KJS::DotAccessorNode::DotAccessorNode): (KJS::ArgumentListNode::ArgumentListNode): (KJS::ArgumentsNode::ArgumentsNode): (KJS::NewExprNode::NewExprNode): (KJS::FunctionCallValueNode::FunctionCallValueNode): (KJS::FunctionCallResolveNode::FunctionCallResolveNode): (KJS::FunctionCallBracketNode::FunctionCallBracketNode): (KJS::FunctionCallDotNode::FunctionCallDotNode): (KJS::PostfixNode::PostfixNode): (KJS::DeleteNode::DeleteNode): (KJS::VoidNode::VoidNode): (KJS::TypeOfNode::TypeOfNode): (KJS::PrefixNode::PrefixNode): (KJS::UnaryPlusNode::UnaryPlusNode): (KJS::NegateNode::NegateNode): (KJS::BitwiseNotNode::BitwiseNotNode): (KJS::LogicalNotNode::LogicalNotNode): (KJS::MultNode::MultNode): (KJS::AddNode::AddNode): (KJS::ShiftNode::ShiftNode): (KJS::RelationalNode::RelationalNode): (KJS::EqualNode::EqualNode): (KJS::BitOperNode::BitOperNode): (KJS::BinaryLogicalNode::BinaryLogicalNode): (KJS::ConditionalNode::ConditionalNode): (KJS::AssignResolveNode::AssignResolveNode): (KJS::AssignBracketNode::AssignBracketNode): (KJS::AssignDotNode::AssignDotNode): (KJS::CommaNode::CommaNode): (KJS::AssignExprNode::AssignExprNode): (KJS::VarDeclListNode::VarDeclListNode): (KJS::VarStatementNode::VarStatementNode): (KJS::ExprStatementNode::ExprStatementNode): (KJS::IfNode::IfNode): (KJS::DoWhileNode::DoWhileNode): (KJS::WhileNode::WhileNode): (KJS::ForNode::ForNode): (KJS::ReturnNode::ReturnNode): (KJS::WithNode::WithNode): (KJS::CaseClauseNode::CaseClauseNode): (KJS::ClauseListNode::ClauseListNode): (KJS::ClauseListNode::clause): (KJS::ClauseListNode::next): (KJS::SwitchNode::SwitchNode): (KJS::LabelNode::LabelNode): (KJS::ThrowNode::ThrowNode): (KJS::CatchNode::CatchNode): (KJS::FinallyNode::FinallyNode): (KJS::TryNode::TryNode): (KJS::ParameterNode::ParameterNode): (KJS::ParameterNode::nextParam): (KJS::FuncDeclNode::FuncDeclNode): (KJS::FuncExprNode::FuncExprNode):
  • kjs/nodes2string.cpp: (KJS::SourceStream::operator<<): (ElementNode::streamTo): (PropertyValueNode::streamTo): (ArgumentListNode::streamTo): (StatListNode::streamTo): (VarDeclListNode::streamTo): (CaseBlockNode::streamTo): (ParameterNode::streamTo): (SourceElementsNode::streamTo):
  • kjs/shared_ptr.h: Added. (kxmlcore::SharedPtr::SharedPtr): (kxmlcore::SharedPtr::~SharedPtr): (kxmlcore::SharedPtr::isNull): (kxmlcore::SharedPtr::notNull): (kxmlcore::SharedPtr::reset): (kxmlcore::SharedPtr::get): (kxmlcore::SharedPtr::operator*): (kxmlcore::SharedPtr::operator->): (kxmlcore::SharedPtr::operator!): (kxmlcore::SharedPtr::operator bool): (kxmlcore::SharedPtr::operator==): (kxmlcore::::operator): (kxmlcore::operator!=): (kxmlcore::static_pointer_cast): (kxmlcore::const_pointer_cast):
File:
1 edited

Legend:

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

    r10154 r10352  
    2727
    2828#include "fast_malloc.h"
     29#include "shared_ptr.h"
    2930
    3031#include "internal.h"
     
    9293  public:
    9394    // reference counting mechanism
    94     virtual void ref() { refcount++; }
    95 #ifdef KJS_DEBUG_MEM
    96     virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }
    97 #else
    98     virtual bool deref() { return (!--refcount); }
    99 #endif
    100 
    101 
    102 #ifdef KJS_DEBUG_MEM
    103     static void finalCheck();
    104 #endif
     95    void ref() { ++m_refcount; }
     96    void deref() { --m_refcount; if (!m_refcount) delete this; }
     97
    10598  protected:
    10699    ValueImp *throwError(ExecState *exec, ErrorType e, const char *msg);
     
    114107    int line;
    115108    UString sourceURL;
    116     unsigned int refcount;
     109    unsigned int m_refcount;
    117110    virtual int sourceId() const { return -1; }
    118111  private:
    119 #ifdef KJS_DEBUG_MEM
    120     // List of all nodes, for debugging purposes. Don't remove!
    121     static std::list<Node *> *s_nodes;
    122 #endif
    123112    // disallow assignment
    124113    Node& operator=(const Node&);
     
    165154  class NumberNode : public Node {
    166155  public:
    167     NumberNode(double v) : value(v) { }
     156    NumberNode(double v) : value(v) {}
    168157    ValueImp *evaluate(ExecState *exec);
    169158    virtual void streamTo(SourceStream &s) const;
     
    211200  public:
    212201    GroupNode(Node *g) : group(g) { }
    213     virtual void ref();
    214     virtual bool deref();
    215202    virtual ValueImp *evaluate(ExecState *exec);
    216203    virtual Reference evaluateReference(ExecState *exec);
    217204    virtual void streamTo(SourceStream &s) const;
    218205  private:
    219     Node *group;
     206    kxmlcore::SharedPtr<Node> group;
    220207  };
    221208
     
    226213    ElementNode(ElementNode *l, int e, Node *n)
    227214      : list(l->list), elision(e), node(n) { l->list = this; }
    228     virtual void ref();
    229     virtual bool deref();
    230215    ValueImp *evaluate(ExecState *exec);
    231216    virtual void streamTo(SourceStream &s) const;
    232217  private:
    233218    friend class ArrayNode;
    234     ElementNode *list;
     219    kxmlcore::SharedPtr<ElementNode> list;
    235220    int elision;
    236     Node *node;
     221    kxmlcore::SharedPtr<Node> node;
    237222  };
    238223
     
    244229    ArrayNode(int eli, ElementNode *ele)
    245230      : element(ele->list), elision(eli), opt(true) { ele->list = 0; }
    246     virtual void ref();
    247     virtual bool deref();
    248     ValueImp *evaluate(ExecState *exec);
    249     virtual void streamTo(SourceStream &s) const;
    250   private:
    251     ElementNode *element;
     231    ValueImp *evaluate(ExecState *exec);
     232    virtual void streamTo(SourceStream &s) const;
     233  private:
     234    kxmlcore::SharedPtr<ElementNode> element;
    252235    int elision;
    253236    bool opt;
     
    261244    PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)
    262245      : name(n), assign(a), list(l->list) { l->list = this; }
    263     virtual void ref();
    264     virtual bool deref();
    265246    ValueImp *evaluate(ExecState *exec);
    266247    virtual void streamTo(SourceStream &s) const;
    267248  private:
    268249    friend class ObjectLiteralNode;
    269     PropertyNode *name;
    270     Node *assign;
    271     PropertyValueNode *list;
     250    kxmlcore::SharedPtr<PropertyNode> name;
     251    kxmlcore::SharedPtr<Node> assign;
     252    kxmlcore::SharedPtr<PropertyValueNode> list;
    272253  };
    273254
     
    276257    ObjectLiteralNode() : list(0) { }
    277258    ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }
    278     virtual void ref();
    279     virtual bool deref();
    280     ValueImp *evaluate(ExecState *exec);
    281     virtual void streamTo(SourceStream &s) const;
    282   private:
    283     PropertyValueNode *list;
     259    ValueImp *evaluate(ExecState *exec);
     260    virtual void streamTo(SourceStream &s) const;
     261  private:
     262    kxmlcore::SharedPtr<PropertyValueNode> list;
    284263  };
    285264
     
    298277  public:
    299278    BracketAccessorNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    300     virtual void ref();
    301     virtual bool deref();
    302279    ValueImp *evaluate(ExecState *exec);
    303280    virtual Reference evaluateReference(ExecState *exec);
    304281    virtual void streamTo(SourceStream &s) const;
    305282  private:
    306     Node *expr1;
    307     Node *expr2;
     283    kxmlcore::SharedPtr<Node> expr1;
     284    kxmlcore::SharedPtr<Node> expr2;
    308285  };
    309286
     
    311288  public:
    312289    DotAccessorNode(Node *e, const Identifier &s) : expr(e), ident(s) { }
    313     virtual void ref();
    314     virtual bool deref();
    315290    ValueImp *evaluate(ExecState *exec);
    316291    virtual Reference evaluateReference(ExecState *exec);
    317292    virtual void streamTo(SourceStream &s) const;
    318293  private:
    319     Node *expr;
     294    kxmlcore::SharedPtr<Node> expr;
    320295    Identifier ident;
    321296  };
     
    327302    ArgumentListNode(ArgumentListNode *l, Node *e)
    328303      : list(l->list), expr(e) { l->list = this; }
    329     virtual void ref();
    330     virtual bool deref();
    331304    ValueImp *evaluate(ExecState *exec);
    332305    List evaluateList(ExecState *exec);
     
    334307  private:
    335308    friend class ArgumentsNode;
    336     ArgumentListNode *list;
    337     Node *expr;
     309    kxmlcore::SharedPtr<ArgumentListNode> list;
     310    kxmlcore::SharedPtr<Node> expr;
    338311  };
    339312
     
    343316    ArgumentsNode(ArgumentListNode *l)
    344317      : list(l->list) { l->list = 0; }
    345     virtual void ref();
    346     virtual bool deref();
    347318    ValueImp *evaluate(ExecState *exec);
    348319    List evaluateList(ExecState *exec);
    349320    virtual void streamTo(SourceStream &s) const;
    350321  private:
    351     ArgumentListNode *list;
     322    kxmlcore::SharedPtr<ArgumentListNode> list;
    352323  };
    353324
     
    356327    NewExprNode(Node *e) : expr(e), args(0) {}
    357328    NewExprNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    358     virtual void ref();
    359     virtual bool deref();
    360     ValueImp *evaluate(ExecState *exec);
    361     virtual void streamTo(SourceStream &s) const;
    362   private:
    363     Node *expr;
    364     ArgumentsNode *args;
     329    ValueImp *evaluate(ExecState *exec);
     330    virtual void streamTo(SourceStream &s) const;
     331  private:
     332    kxmlcore::SharedPtr<Node> expr;
     333    kxmlcore::SharedPtr<ArgumentsNode> args;
    365334  };
    366335
     
    368337  public:
    369338    FunctionCallValueNode(Node *e, ArgumentsNode *a) : expr(e), args(a) {}
    370     virtual void ref();
    371     virtual bool deref();
    372     ValueImp *evaluate(ExecState *exec);
    373     virtual void streamTo(SourceStream &s) const;
    374   private:
    375     Node *expr;
    376     ArgumentsNode *args;
     339    ValueImp *evaluate(ExecState *exec);
     340    virtual void streamTo(SourceStream &s) const;
     341  private:
     342    kxmlcore::SharedPtr<Node> expr;
     343    kxmlcore::SharedPtr<ArgumentsNode> args;
    377344  };
    378345
     
    380347  public:
    381348    FunctionCallResolveNode(const Identifier& i, ArgumentsNode *a) : ident(i), args(a) {}
    382     virtual void ref();
    383     virtual bool deref();
    384349    ValueImp *evaluate(ExecState *exec);
    385350    virtual void streamTo(SourceStream &s) const;
    386351  private:
    387352    Identifier ident;
    388     ArgumentsNode *args;
     353    kxmlcore::SharedPtr<ArgumentsNode> args;
    389354  };
    390355
     
    392357  public:
    393358    FunctionCallBracketNode(Node *b, Node *s, ArgumentsNode *a) : base(b), subscript(s), args(a) {}
    394     virtual void ref();
    395     virtual bool deref();
    396359    ValueImp *evaluate(ExecState *exec);
    397360    virtual void streamTo(SourceStream &s) const;
    398361  protected:
    399     Node *base;
    400     Node *subscript;
    401     ArgumentsNode *args;
     362    kxmlcore::SharedPtr<Node> base;
     363    kxmlcore::SharedPtr<Node> subscript;
     364    kxmlcore::SharedPtr<ArgumentsNode> args;
    402365  };
    403366
     
    411374  public:
    412375    FunctionCallDotNode(Node *b, const Identifier &i, ArgumentsNode *a) : base(b), ident(i), args(a) {}
    413     virtual void ref();
    414     virtual bool deref();
    415376    ValueImp *evaluate(ExecState *exec);
    416377    virtual void streamTo(SourceStream &s) const;
    417378  protected:
    418     Node *base;
     379    kxmlcore::SharedPtr<Node> base;
    419380    Identifier ident;
    420     ArgumentsNode *args;
     381    kxmlcore::SharedPtr<ArgumentsNode> args;
    421382  };
    422383
     
    430391  public:
    431392    PostfixNode(Node *e, Operator o) : expr(e), oper(o) {}
    432     virtual void ref();
    433     virtual bool deref();
    434     ValueImp *evaluate(ExecState *exec);
    435     virtual void streamTo(SourceStream &s) const;
    436   private:
    437     Node *expr;
     393    ValueImp *evaluate(ExecState *exec);
     394    virtual void streamTo(SourceStream &s) const;
     395  private:
     396    kxmlcore::SharedPtr<Node> expr;
    438397    Operator oper;
    439398  };
     
    442401  public:
    443402    DeleteNode(Node *e) : expr(e) {}
    444     virtual void ref();
    445     virtual bool deref();
    446     ValueImp *evaluate(ExecState *exec);
    447     virtual void streamTo(SourceStream &s) const;
    448   private:
    449     Node *expr;
     403    ValueImp *evaluate(ExecState *exec);
     404    virtual void streamTo(SourceStream &s) const;
     405  private:
     406    kxmlcore::SharedPtr<Node> expr;
    450407  };
    451408
     
    453410  public:
    454411    VoidNode(Node *e) : expr(e) {}
    455     virtual void ref();
    456     virtual bool deref();
    457     ValueImp *evaluate(ExecState *exec);
    458     virtual void streamTo(SourceStream &s) const;
    459   private:
    460     Node *expr;
     412    ValueImp *evaluate(ExecState *exec);
     413    virtual void streamTo(SourceStream &s) const;
     414  private:
     415    kxmlcore::SharedPtr<Node> expr;
    461416  };
    462417
     
    464419  public:
    465420    TypeOfNode(Node *e) : expr(e) {}
    466     virtual void ref();
    467     virtual bool deref();
    468     ValueImp *evaluate(ExecState *exec);
    469     virtual void streamTo(SourceStream &s) const;
    470   private:
    471     Node *expr;
     421    ValueImp *evaluate(ExecState *exec);
     422    virtual void streamTo(SourceStream &s) const;
     423  private:
     424    kxmlcore::SharedPtr<Node> expr;
    472425  };
    473426
     
    475428  public:
    476429    PrefixNode(Operator o, Node *e) : oper(o), expr(e) {}
    477     virtual void ref();
    478     virtual bool deref();
    479430    ValueImp *evaluate(ExecState *exec);
    480431    virtual void streamTo(SourceStream &s) const;
    481432  private:
    482433    Operator oper;
    483     Node *expr;
     434    kxmlcore::SharedPtr<Node> expr;
    484435  };
    485436
     
    487438  public:
    488439    UnaryPlusNode(Node *e) : expr(e) {}
    489     virtual void ref();
    490     virtual bool deref();
    491     ValueImp *evaluate(ExecState *exec);
    492     virtual void streamTo(SourceStream &s) const;
    493   private:
    494     Node *expr;
     440    ValueImp *evaluate(ExecState *exec);
     441    virtual void streamTo(SourceStream &s) const;
     442  private:
     443    kxmlcore::SharedPtr<Node> expr;
    495444  };
    496445
     
    498447  public:
    499448    NegateNode(Node *e) : expr(e) {}
    500     virtual void ref();
    501     virtual bool deref();
    502     ValueImp *evaluate(ExecState *exec);
    503     virtual void streamTo(SourceStream &s) const;
    504   private:
    505     Node *expr;
     449    ValueImp *evaluate(ExecState *exec);
     450    virtual void streamTo(SourceStream &s) const;
     451  private:
     452    kxmlcore::SharedPtr<Node> expr;
    506453  };
    507454
     
    509456  public:
    510457    BitwiseNotNode(Node *e) : expr(e) {}
    511     virtual void ref();
    512     virtual bool deref();
    513     ValueImp *evaluate(ExecState *exec);
    514     virtual void streamTo(SourceStream &s) const;
    515   private:
    516     Node *expr;
     458    ValueImp *evaluate(ExecState *exec);
     459    virtual void streamTo(SourceStream &s) const;
     460  private:
     461    kxmlcore::SharedPtr<Node> expr;
    517462  };
    518463
     
    520465  public:
    521466    LogicalNotNode(Node *e) : expr(e) {}
    522     virtual void ref();
    523     virtual bool deref();
    524     ValueImp *evaluate(ExecState *exec);
    525     virtual void streamTo(SourceStream &s) const;
    526   private:
    527     Node *expr;
     467    ValueImp *evaluate(ExecState *exec);
     468    virtual void streamTo(SourceStream &s) const;
     469  private:
     470    kxmlcore::SharedPtr<Node> expr;
    528471  };
    529472
     
    531474  public:
    532475    MultNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    533     virtual void ref();
    534     virtual bool deref();
    535     ValueImp *evaluate(ExecState *exec);
    536     virtual void streamTo(SourceStream &s) const;
    537   private:
    538     Node *term1, *term2;
     476    ValueImp *evaluate(ExecState *exec);
     477    virtual void streamTo(SourceStream &s) const;
     478  private:
     479    kxmlcore::SharedPtr<Node> term1;
     480    kxmlcore::SharedPtr<Node> term2;
    539481    char oper;
    540482  };
     
    543485  public:
    544486    AddNode(Node *t1, Node *t2, char op) : term1(t1), term2(t2), oper(op) {}
    545     virtual void ref();
    546     virtual bool deref();
    547     ValueImp *evaluate(ExecState *exec);
    548     virtual void streamTo(SourceStream &s) const;
    549   private:
    550     Node *term1, *term2;
     487    ValueImp *evaluate(ExecState *exec);
     488    virtual void streamTo(SourceStream &s) const;
     489  private:
     490    kxmlcore::SharedPtr<Node> term1;
     491    kxmlcore::SharedPtr<Node> term2;
    551492    char oper;
    552493  };
     
    556497    ShiftNode(Node *t1, Operator o, Node *t2)
    557498      : term1(t1), term2(t2), oper(o) {}
    558     virtual void ref();
    559     virtual bool deref();
    560     ValueImp *evaluate(ExecState *exec);
    561     virtual void streamTo(SourceStream &s) const;
    562   private:
    563     Node *term1, *term2;
     499    ValueImp *evaluate(ExecState *exec);
     500    virtual void streamTo(SourceStream &s) const;
     501  private:
     502    kxmlcore::SharedPtr<Node> term1;
     503    kxmlcore::SharedPtr<Node> term2;
    564504    Operator oper;
    565505  };
     
    569509    RelationalNode(Node *e1, Operator o, Node *e2) :
    570510      expr1(e1), expr2(e2), oper(o) {}
    571     virtual void ref();
    572     virtual bool deref();
    573     ValueImp *evaluate(ExecState *exec);
    574     virtual void streamTo(SourceStream &s) const;
    575   private:
    576     Node *expr1, *expr2;
     511    ValueImp *evaluate(ExecState *exec);
     512    virtual void streamTo(SourceStream &s) const;
     513  private:
     514    kxmlcore::SharedPtr<Node> expr1;
     515    kxmlcore::SharedPtr<Node> expr2;
    577516    Operator oper;
    578517  };
     
    582521    EqualNode(Node *e1, Operator o, Node *e2)
    583522      : expr1(e1), expr2(e2), oper(o) {}
    584     virtual void ref();
    585     virtual bool deref();
    586     ValueImp *evaluate(ExecState *exec);
    587     virtual void streamTo(SourceStream &s) const;
    588   private:
    589     Node *expr1, *expr2;
     523    ValueImp *evaluate(ExecState *exec);
     524    virtual void streamTo(SourceStream &s) const;
     525  private:
     526    kxmlcore::SharedPtr<Node> expr1;
     527    kxmlcore::SharedPtr<Node> expr2;
    590528    Operator oper;
    591529  };
     
    595533    BitOperNode(Node *e1, Operator o, Node *e2) :
    596534      expr1(e1), expr2(e2), oper(o) {}
    597     virtual void ref();
    598     virtual bool deref();
    599     ValueImp *evaluate(ExecState *exec);
    600     virtual void streamTo(SourceStream &s) const;
    601   private:
    602     Node *expr1, *expr2;
     535    ValueImp *evaluate(ExecState *exec);
     536    virtual void streamTo(SourceStream &s) const;
     537  private:
     538    kxmlcore::SharedPtr<Node> expr1;
     539    kxmlcore::SharedPtr<Node> expr2;
    603540    Operator oper;
    604541  };
     
    611548    BinaryLogicalNode(Node *e1, Operator o, Node *e2) :
    612549      expr1(e1), expr2(e2), oper(o) {}
    613     virtual void ref();
    614     virtual bool deref();
    615     ValueImp *evaluate(ExecState *exec);
    616     virtual void streamTo(SourceStream &s) const;
    617   private:
    618     Node *expr1, *expr2;
     550    ValueImp *evaluate(ExecState *exec);
     551    virtual void streamTo(SourceStream &s) const;
     552  private:
     553    kxmlcore::SharedPtr<Node> expr1;
     554    kxmlcore::SharedPtr<Node> expr2;
    619555    Operator oper;
    620556  };
     
    627563    ConditionalNode(Node *l, Node *e1, Node *e2) :
    628564      logical(l), expr1(e1), expr2(e2) {}
    629     virtual void ref();
    630     virtual bool deref();
    631     ValueImp *evaluate(ExecState *exec);
    632     virtual void streamTo(SourceStream &s) const;
    633   private:
    634     Node *logical, *expr1, *expr2;
     565    ValueImp *evaluate(ExecState *exec);
     566    virtual void streamTo(SourceStream &s) const;
     567  private:
     568    kxmlcore::SharedPtr<Node> logical;
     569    kxmlcore::SharedPtr<Node> expr1;
     570    kxmlcore::SharedPtr<Node> expr2;
    635571  };
    636572
     
    639575    AssignResolveNode(const Identifier &ident, Operator oper, Node *right)
    640576      : m_ident(ident), m_oper(oper), m_right(right) {}
    641     virtual void ref();
    642     virtual bool deref();
    643577    ValueImp *evaluate(ExecState *exec);
    644578    virtual void streamTo(SourceStream &s) const;
     
    646580    Identifier m_ident;
    647581    Operator m_oper;
    648     Node *m_right;
     582    kxmlcore::SharedPtr<Node> m_right;
    649583  };
    650584
     
    653587    AssignBracketNode(Node *base, Node *subscript, Operator oper, Node *right)
    654588      : m_base(base), m_subscript(subscript), m_oper(oper), m_right(right) {}
    655     virtual void ref();
    656     virtual bool deref();
    657589    ValueImp *evaluate(ExecState *exec);
    658590    virtual void streamTo(SourceStream &s) const;
    659591  protected:
    660     Node *m_base;
    661     Node *m_subscript;
     592    kxmlcore::SharedPtr<Node> m_base;
     593    kxmlcore::SharedPtr<Node> m_subscript;
    662594    Operator m_oper;
    663     Node *m_right;
     595    kxmlcore::SharedPtr<Node> m_right;
    664596  };
    665597
     
    668600    AssignDotNode(Node *base, const Identifier& ident, Operator oper, Node *right)
    669601      : m_base(base), m_ident(ident), m_oper(oper), m_right(right) {}
    670     virtual void ref();
    671     virtual bool deref();
    672602    ValueImp *evaluate(ExecState *exec);
    673603    virtual void streamTo(SourceStream &s) const;
    674604  protected:
    675     Node *m_base;
     605    kxmlcore::SharedPtr<Node> m_base;
    676606    Identifier m_ident;
    677607    Operator m_oper;
    678     Node *m_right;
     608    kxmlcore::SharedPtr<Node> m_right;
    679609  };
    680610
     
    682612  public:
    683613    CommaNode(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}
    684     virtual void ref();
    685     virtual bool deref();
    686     ValueImp *evaluate(ExecState *exec);
    687     virtual void streamTo(SourceStream &s) const;
    688   private:
    689     Node *expr1, *expr2;
     614    ValueImp *evaluate(ExecState *exec);
     615    virtual void streamTo(SourceStream &s) const;
     616  private:
     617    kxmlcore::SharedPtr<Node> expr1;
     618    kxmlcore::SharedPtr<Node> expr2;
    690619  };
    691620
     
    695624    StatListNode(StatementNode *s);
    696625    StatListNode(StatListNode *l, StatementNode *s);
    697     virtual void ref();
    698     virtual bool deref();
    699626    virtual Completion execute(ExecState *exec);
    700627    virtual void processVarDecls(ExecState *exec);
     
    702629  private:
    703630    friend class CaseClauseNode;
    704     StatementNode *statement;
    705     StatListNode *list;
     631    kxmlcore::SharedPtr<StatementNode> statement;
     632    kxmlcore::SharedPtr<StatListNode> list;
    706633  };
    707634
     
    709636  public:
    710637    AssignExprNode(Node *e) : expr(e) {}
    711     virtual void ref();
    712     virtual bool deref();
    713     ValueImp *evaluate(ExecState *exec);
    714     virtual void streamTo(SourceStream &s) const;
    715   private:
    716     Node *expr;
     638    ValueImp *evaluate(ExecState *exec);
     639    virtual void streamTo(SourceStream &s) const;
     640  private:
     641    kxmlcore::SharedPtr<Node> expr;
    717642  };
    718643
     
    721646    enum Type { Variable, Constant };
    722647    VarDeclNode(const Identifier &id, AssignExprNode *in, Type t);
    723     virtual void ref();
    724     virtual bool deref();
    725648    ValueImp *evaluate(ExecState *exec);
    726649    virtual void processVarDecls(ExecState *exec);
     
    729652    Type varType;
    730653    Identifier ident;
    731     AssignExprNode *init;
     654    kxmlcore::SharedPtr<AssignExprNode> init;
    732655  };
    733656
     
    738661    VarDeclListNode(VarDeclListNode *l, VarDeclNode *v)
    739662      : list(l->list), var(v) { l->list = this; }
    740     virtual void ref();
    741     virtual bool deref();
    742663    ValueImp *evaluate(ExecState *exec);
    743664    virtual void processVarDecls(ExecState *exec);
     
    746667    friend class ForNode;
    747668    friend class VarStatementNode;
    748     VarDeclListNode *list;
    749     VarDeclNode *var;
     669    kxmlcore::SharedPtr<VarDeclListNode> list;
     670    kxmlcore::SharedPtr<VarDeclNode> var;
    750671  };
    751672
     
    753674  public:
    754675    VarStatementNode(VarDeclListNode *l) : list(l->list) { l->list = 0; }
    755     virtual void ref();
    756     virtual bool deref();
    757     virtual Completion execute(ExecState *exec);
    758     virtual void processVarDecls(ExecState *exec);
    759     virtual void streamTo(SourceStream &s) const;
    760   private:
    761     VarDeclListNode *list;
     676    virtual Completion execute(ExecState *exec);
     677    virtual void processVarDecls(ExecState *exec);
     678    virtual void streamTo(SourceStream &s) const;
     679  private:
     680    kxmlcore::SharedPtr<VarDeclListNode> list;
    762681  };
    763682
     
    765684  public:
    766685    BlockNode(SourceElementsNode *s);
    767     virtual void ref();
    768     virtual bool deref();
    769686    virtual Completion execute(ExecState *exec);
    770687    virtual void processVarDecls(ExecState *exec);
    771688    virtual void streamTo(SourceStream &s) const;
    772689  protected:
    773     SourceElementsNode *source;
     690    kxmlcore::SharedPtr<SourceElementsNode> source;
    774691  };
    775692
     
    784701  public:
    785702    ExprStatementNode(Node *e) : expr(e) { }
    786     virtual void ref();
    787     virtual bool deref();
    788     virtual Completion execute(ExecState *exec);
    789     virtual void streamTo(SourceStream &s) const;
    790   private:
    791     Node *expr;
     703    virtual Completion execute(ExecState *exec);
     704    virtual void streamTo(SourceStream &s) const;
     705  private:
     706    kxmlcore::SharedPtr<Node> expr;
    792707  };
    793708
     
    796711    IfNode(Node *e, StatementNode *s1, StatementNode *s2)
    797712      : expr(e), statement1(s1), statement2(s2) {}
    798     virtual void ref();
    799     virtual bool deref();
    800     virtual Completion execute(ExecState *exec);
    801     virtual void processVarDecls(ExecState *exec);
    802     virtual void streamTo(SourceStream &s) const;
    803   private:
    804     Node *expr;
    805     StatementNode *statement1, *statement2;
     713    virtual Completion execute(ExecState *exec);
     714    virtual void processVarDecls(ExecState *exec);
     715    virtual void streamTo(SourceStream &s) const;
     716  private:
     717    kxmlcore::SharedPtr<Node> expr;
     718    kxmlcore::SharedPtr<StatementNode> statement1;
     719    kxmlcore::SharedPtr<StatementNode> statement2;
    806720  };
    807721
     
    809723  public:
    810724    DoWhileNode(StatementNode *s, Node *e) : statement(s), expr(e) {}
    811     virtual void ref();
    812     virtual bool deref();
    813     virtual Completion execute(ExecState *exec);
    814     virtual void processVarDecls(ExecState *exec);
    815     virtual void streamTo(SourceStream &s) const;
    816   private:
    817     StatementNode *statement;
    818     Node *expr;
     725    virtual Completion execute(ExecState *exec);
     726    virtual void processVarDecls(ExecState *exec);
     727    virtual void streamTo(SourceStream &s) const;
     728  private:
     729    kxmlcore::SharedPtr<StatementNode> statement;
     730    kxmlcore::SharedPtr<Node> expr;
    819731  };
    820732
     
    822734  public:
    823735    WhileNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
    824     virtual void ref();
    825     virtual bool deref();
    826     virtual Completion execute(ExecState *exec);
    827     virtual void processVarDecls(ExecState *exec);
    828     virtual void streamTo(SourceStream &s) const;
    829   private:
    830     Node *expr;
    831     StatementNode *statement;
     736    virtual Completion execute(ExecState *exec);
     737    virtual void processVarDecls(ExecState *exec);
     738    virtual void streamTo(SourceStream &s) const;
     739  private:
     740    kxmlcore::SharedPtr<Node> expr;
     741    kxmlcore::SharedPtr<StatementNode> statement;
    832742  };
    833743
     
    838748    ForNode(VarDeclListNode *e1, Node *e2, Node *e3, StatementNode *s) :
    839749      expr1(e1->list), expr2(e2), expr3(e3), statement(s) { e1->list = 0; }
    840     virtual void ref();
    841     virtual bool deref();
    842     virtual Completion execute(ExecState *exec);
    843     virtual void processVarDecls(ExecState *exec);
    844     virtual void streamTo(SourceStream &s) const;
    845   private:
    846     Node *expr1, *expr2, *expr3;
    847     StatementNode *statement;
     750    virtual Completion execute(ExecState *exec);
     751    virtual void processVarDecls(ExecState *exec);
     752    virtual void streamTo(SourceStream &s) const;
     753  private:
     754    kxmlcore::SharedPtr<Node> expr1;
     755    kxmlcore::SharedPtr<Node> expr2;
     756    kxmlcore::SharedPtr<Node> expr3;
     757    kxmlcore::SharedPtr<StatementNode> statement;
    848758  };
    849759
     
    852762    ForInNode(Node *l, Node *e, StatementNode *s);
    853763    ForInNode(const Identifier &i, AssignExprNode *in, Node *e, StatementNode *s);
    854     virtual void ref();
    855     virtual bool deref();
    856764    virtual Completion execute(ExecState *exec);
    857765    virtual void processVarDecls(ExecState *exec);
     
    859767  private:
    860768    Identifier ident;
    861     AssignExprNode *init;
    862     Node *lexpr, *expr;
    863     VarDeclNode *varDecl;
    864     StatementNode *statement;
     769    kxmlcore::SharedPtr<AssignExprNode> init;
     770    kxmlcore::SharedPtr<Node> lexpr;
     771    kxmlcore::SharedPtr<Node> expr;
     772    kxmlcore::SharedPtr<VarDeclNode> varDecl;
     773    kxmlcore::SharedPtr<StatementNode> statement;
    865774  };
    866775
     
    888797  public:
    889798    ReturnNode(Node *v) : value(v) {}
    890     virtual void ref();
    891     virtual bool deref();
    892     virtual Completion execute(ExecState *exec);
    893     virtual void streamTo(SourceStream &s) const;
    894   private:
    895     Node *value;
     799    virtual Completion execute(ExecState *exec);
     800    virtual void streamTo(SourceStream &s) const;
     801  private:
     802    kxmlcore::SharedPtr<Node> value;
    896803  };
    897804
     
    899806  public:
    900807    WithNode(Node *e, StatementNode *s) : expr(e), statement(s) {}
    901     virtual void ref();
    902     virtual bool deref();
    903     virtual Completion execute(ExecState *exec);
    904     virtual void processVarDecls(ExecState *exec);
    905     virtual void streamTo(SourceStream &s) const;
    906   private:
    907     Node *expr;
    908     StatementNode *statement;
     808    virtual Completion execute(ExecState *exec);
     809    virtual void processVarDecls(ExecState *exec);
     810    virtual void streamTo(SourceStream &s) const;
     811  private:
     812    kxmlcore::SharedPtr<Node> expr;
     813    kxmlcore::SharedPtr<StatementNode> statement;
    909814  };
    910815
     
    914819    CaseClauseNode(Node *e, StatListNode *l)
    915820      : expr(e), list(l->list) { l->list = 0; }
    916     virtual void ref();
    917     virtual bool deref();
    918821    ValueImp *evaluate(ExecState *exec);
    919822    Completion evalStatements(ExecState *exec);
     
    921824    virtual void streamTo(SourceStream &s) const;
    922825  private:
    923     Node *expr;
    924     StatListNode *list;
     826    kxmlcore::SharedPtr<Node> expr;
     827    kxmlcore::SharedPtr<StatListNode> list;
    925828  };
    926829
     
    931834    ClauseListNode(ClauseListNode *n, CaseClauseNode *c)
    932835      : cl(c), nx(n->nx) { n->nx = this; }
    933     virtual void ref();
    934     virtual bool deref();
    935     ValueImp *evaluate(ExecState *exec);
    936     CaseClauseNode *clause() const { return cl; }
    937     ClauseListNode *next() const { return nx; }
     836    ValueImp *evaluate(ExecState *exec);
     837    CaseClauseNode *clause() const { return cl.get(); }
     838    ClauseListNode *next() const { return nx.get(); }
    938839    virtual void processVarDecls(ExecState *exec);
    939840    virtual void streamTo(SourceStream &s) const;
    940841  private:
    941842    friend class CaseBlockNode;
    942     CaseClauseNode *cl;
    943     ClauseListNode *nx;
     843    kxmlcore::SharedPtr<CaseClauseNode> cl;
     844    kxmlcore::SharedPtr<ClauseListNode> nx;
    944845  };
    945846
     
    947848  public:
    948849    CaseBlockNode(ClauseListNode *l1, CaseClauseNode *d, ClauseListNode *l2);
    949     virtual void ref();
    950     virtual bool deref();
    951850    ValueImp *evaluate(ExecState *exec);
    952851    Completion evalBlock(ExecState *exec, ValueImp *input);
     
    954853    virtual void streamTo(SourceStream &s) const;
    955854  private:
    956     ClauseListNode *list1;
    957     CaseClauseNode *def;
    958     ClauseListNode *list2;
     855    kxmlcore::SharedPtr<ClauseListNode> list1;
     856    kxmlcore::SharedPtr<CaseClauseNode> def;
     857    kxmlcore::SharedPtr<ClauseListNode> list2;
    959858  };
    960859
     
    962861  public:
    963862    SwitchNode(Node *e, CaseBlockNode *b) : expr(e), block(b) { }
    964     virtual void ref();
    965     virtual bool deref();
    966     virtual Completion execute(ExecState *exec);
    967     virtual void processVarDecls(ExecState *exec);
    968     virtual void streamTo(SourceStream &s) const;
    969   private:
    970     Node *expr;
    971     CaseBlockNode *block;
     863    virtual Completion execute(ExecState *exec);
     864    virtual void processVarDecls(ExecState *exec);
     865    virtual void streamTo(SourceStream &s) const;
     866  private:
     867    kxmlcore::SharedPtr<Node> expr;
     868    kxmlcore::SharedPtr<CaseBlockNode> block;
    972869  };
    973870
     
    975872  public:
    976873    LabelNode(const Identifier &l, StatementNode *s) : label(l), statement(s) { }
    977     virtual void ref();
    978     virtual bool deref();
    979874    virtual Completion execute(ExecState *exec);
    980875    virtual void processVarDecls(ExecState *exec);
     
    982877  private:
    983878    Identifier label;
    984     StatementNode *statement;
     879    kxmlcore::SharedPtr<StatementNode> statement;
    985880  };
    986881
     
    988883  public:
    989884    ThrowNode(Node *e) : expr(e) {}
    990     virtual void ref();
    991     virtual bool deref();
    992     virtual Completion execute(ExecState *exec);
    993     virtual void streamTo(SourceStream &s) const;
    994   private:
    995     Node *expr;
     885    virtual Completion execute(ExecState *exec);
     886    virtual void streamTo(SourceStream &s) const;
     887  private:
     888    kxmlcore::SharedPtr<Node> expr;
    996889  };
    997890
     
    999892  public:
    1000893    CatchNode(const Identifier &i, StatementNode *b) : ident(i), block(b) {}
    1001     virtual void ref();
    1002     virtual bool deref();
    1003894    virtual Completion execute(ExecState *exec);
    1004895    Completion execute(ExecState *exec, ValueImp *arg);
     
    1007898  private:
    1008899    Identifier ident;
    1009     StatementNode *block;
     900    kxmlcore::SharedPtr<StatementNode> block;
    1010901  };
    1011902
     
    1013904  public:
    1014905    FinallyNode(StatementNode *b) : block(b) {}
    1015     virtual void ref();
    1016     virtual bool deref();
    1017     virtual Completion execute(ExecState *exec);
    1018     virtual void processVarDecls(ExecState *exec);
    1019     virtual void streamTo(SourceStream &s) const;
    1020   private:
    1021     StatementNode *block;
     906    virtual Completion execute(ExecState *exec);
     907    virtual void processVarDecls(ExecState *exec);
     908    virtual void streamTo(SourceStream &s) const;
     909  private:
     910    kxmlcore::SharedPtr<StatementNode> block;
    1022911  };
    1023912
     
    1030919    TryNode(StatementNode *b, CatchNode *c, FinallyNode *f)
    1031920      : block(b), _catch(c), _final(f) {}
    1032     virtual void ref();
    1033     virtual bool deref();
    1034     virtual Completion execute(ExecState *exec);
    1035     virtual void processVarDecls(ExecState *exec);
    1036     virtual void streamTo(SourceStream &s) const;
    1037   private:
    1038     StatementNode *block;
    1039     CatchNode *_catch;
    1040     FinallyNode *_final;
     921    virtual Completion execute(ExecState *exec);
     922    virtual void processVarDecls(ExecState *exec);
     923    virtual void streamTo(SourceStream &s) const;
     924  private:
     925    kxmlcore::SharedPtr<StatementNode> block;
     926    kxmlcore::SharedPtr<CatchNode> _catch;
     927    kxmlcore::SharedPtr<FinallyNode> _final;
    1041928  };
    1042929
     
    1047934    ParameterNode(ParameterNode *list, const Identifier &i)
    1048935      : id(i), next(list->next) { list->next = this; }
    1049     virtual void ref();
    1050     virtual bool deref();
    1051936    ValueImp *evaluate(ExecState *exec);
    1052937    Identifier ident() { return id; }
    1053     ParameterNode *nextParam() { return next; }
     938    ParameterNode *nextParam() { return next.get(); }
    1054939    virtual void streamTo(SourceStream &s) const;
    1055940  private:
     
    1057942    friend class FuncExprNode;
    1058943    Identifier id;
    1059     ParameterNode *next;
     944    kxmlcore::SharedPtr<ParameterNode> next;
    1060945  };
    1061946
     
    1073958    FuncDeclNode(const Identifier &i, ParameterNode *p, FunctionBodyNode *b)
    1074959      : ident(i), param(p->next), body(b) { p->next = 0; }
    1075     virtual void ref();
    1076     virtual bool deref();
    1077960    Completion execute(ExecState */*exec*/)
    1078961      { /* empty */ return Completion(); }
     
    1081964  private:
    1082965    Identifier ident;
    1083     ParameterNode *param;
    1084     FunctionBodyNode *body;
     966    kxmlcore::SharedPtr<ParameterNode> param;
     967    kxmlcore::SharedPtr<FunctionBodyNode> body;
    1085968  };
    1086969
     
    1090973    FuncExprNode(ParameterNode *p, FunctionBodyNode *b)
    1091974      : param(p->next), body(b) { p->next = 0; }
    1092     virtual void ref();
    1093     virtual bool deref();
    1094     ValueImp *evaluate(ExecState *exec);
    1095     virtual void streamTo(SourceStream &s) const;
    1096   private:
    1097     ParameterNode *param;
    1098     FunctionBodyNode *body;
     975    ValueImp *evaluate(ExecState *exec);
     976    virtual void streamTo(SourceStream &s) const;
     977  private:
     978    kxmlcore::SharedPtr<ParameterNode> param;
     979    kxmlcore::SharedPtr<FunctionBodyNode> body;
    1099980  };
    1100981
     
    1105986    SourceElementsNode(StatementNode *s1);
    1106987    SourceElementsNode(SourceElementsNode *s1, StatementNode *s2);
    1107     virtual void ref();
    1108     virtual bool deref();
     988
    1109989    Completion execute(ExecState *exec);
    1110990    void processFuncDecl(ExecState *exec);
     
    1113993  private:
    1114994    friend class BlockNode;
    1115     StatementNode *element; // 'this' element
    1116     SourceElementsNode *elements; // pointer to next
     995    kxmlcore::SharedPtr<StatementNode> element; // 'this' element
     996    kxmlcore::SharedPtr<SourceElementsNode> elements; // pointer to next
    1117997  };
    1118998
Note: See TracChangeset for help on using the changeset viewer.