nodes.h

来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 1,082 行 · 第 1/3 页

H
1,082
字号
// -*- c-basic-offset: 2 -*-/* *  This file is part of the KDE libraries *  Copyright (C) 1999-2000, 2003 Harri Porten (porten@kde.org) *  Copyright (C) 2001 Peter Kelly (pmk@post.com) *  Copyright (C) 2003 Apple Computer, Inc. * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Library General Public *  License as published by the Free Software Foundation; either *  version 2 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  Library General Public License for more details. * *  You should have received a copy of the GNU Library General Public License *  along with this library; see the file COPYING.LIB.  If not, write to *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *  Boston, MA 02110-1301, USA. * */#ifndef _NODES_H_#define _NODES_H_#include "internal.h"//#include "debugger.h"#ifndef NDEBUG#include <list>#include <assert.h>#endifnamespace KJS {  class RegExp;  class SourceElementsNode;  class ObjectLiteralNode;  class PropertyNode;  class SourceStream;  class PropertyValueNode;  class PropertyNode;  enum Operator { OpEqual,		  OpEqEq,		  OpNotEq,		  OpStrEq,		  OpStrNEq,		  OpPlusEq,		  OpMinusEq,		  OpMultEq,		  OpDivEq,                  OpPlusPlus,		  OpMinusMinus,		  OpLess,		  OpLessEq,		  OpGreater,		  OpGreaterEq,		  OpAndEq,		  OpXOrEq,		  OpOrEq,		  OpModEq,                  OpAnd,                  OpOr,		  OpBitAnd,		  OpBitXOr,		  OpBitOr,		  OpLShift,		  OpRShift,		  OpURShift,		  OpIn,		  OpInstanceOf  };  class Node {  public:    Node();    virtual ~Node();    // reusing Value Type here, declare new enum if required    virtual Type type() const { return UnspecifiedType; }    /**     * Evaluate this node and return the result, possibly a reference.     */    virtual Reference evaluateReference(ExecState *exec) const;    /**     * Returns the value represented by this node. Always dereferenced.     */    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual double toNumber(ExecState *exec) const;    virtual UString toString(ExecState *exec) const;    UString toCode() const;    virtual void streamTo(SourceStream &s) const = 0;    virtual void processVarDecls(ExecState* /*exec*/) {}    int lineNo() const { return line; }  public:    // reference counting mechanism    virtual void ref() { refcount++; }#ifdef KJS_DEBUG_MEM    virtual bool deref() { assert( refcount > 0 ); return (!--refcount); }#else    virtual bool deref() { return (!--refcount); }#endif#ifdef KJS_DEBUG_MEM    static void finalCheck();#endif  protected:    Value throwError(ExecState *exec, ErrorType e, const char *msg) const;    Value throwError(ExecState *exec, ErrorType e, const char *msg,                     const Value &v, const Node *expr) const;    Value throwError(ExecState *exec, ErrorType e, const char *msg, Identifier label) const;    void setExceptionDetailsIfNeeded(ExecState *exec) const;    int line;    unsigned int refcount;    virtual int sourceId() const { return -1; }  private:#ifdef KJS_DEBUG_MEM    // List of all nodes, for debugging purposes. Don't remove!    static std::list<Node *> *s_nodes;#endif    // disallow assignment    Node& operator=(const Node&);    Node(const Node &other);  };  class StatementNode : public Node {  public:    StatementNode();    virtual ~StatementNode();    void setLoc(int line0, int line1, SourceCode *src);    int firstLine() const { return l0; }    int lastLine() const { return l1; }    int sourceId() const { return sourceCode->sid; }    SourceCode *code() const { return sourceCode; }    bool hitStatement(ExecState *exec);    bool abortStatement(ExecState *exec);    virtual Completion execute(ExecState *exec) = 0;    void pushLabel(const Identifier &id) { ls.push(id); }    virtual void processFuncDecl(ExecState *exec);  protected:    LabelStack ls;  private:    Reference evaluateReference(ExecState* /*exec*/) const { return Reference(0,Identifier::null()); }    int l0, l1;    SourceCode *sourceCode;    bool breakPoint;  };  class NullNode : public Node {  public:    NullNode() {}    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual double toNumber(ExecState *exec) const;    virtual UString toString(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  };  class BooleanNode : public Node {  public:    BooleanNode(bool v) : val(v) {}    virtual Type type() const { return BooleanType; }    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual double toNumber(ExecState *exec) const;    virtual UString toString(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    bool val;  };  class NumberNode : public Node {  public:    NumberNode(double v) : val(v) { }    virtual Type type() const { return NumberType; }    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual double toNumber(ExecState *exec) const;    virtual UString toString(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    double val;  };  class StringNode : public Node {  public:    StringNode(const UString *v) : val(*v) { }    virtual Type type() const { return StringType; }    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual double toNumber(ExecState *exec) const;    virtual UString toString(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    UString val;  };  class RegExpNode : public Node {  public:    RegExpNode(const UString &p, const UString &f)      : pattern(p), flags(f) { }    virtual Value evaluate(ExecState *exec) const;    virtual bool toBoolean(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    UString pattern, flags;  };  class ThisNode : public Node {  public:    ThisNode() {}    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  };  class ResolveNode : public Node {  public:    ResolveNode(const Identifier &s) : ident(s) { }    Reference evaluateReference(ExecState *exec) const;    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    Identifier ident;  };  class GroupNode : public Node {  public:    GroupNode(Node *g) : group(g) { }    virtual void ref();    virtual bool deref();    Reference evaluateReference(ExecState *exec) const;    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    Node *group;  };  class ElementNode : public Node {  public:    // list is circular during construction. cracked in ArrayNode ctor    ElementNode(int e, Node *n) : list(this), elision(e), node(n) { }    ElementNode(ElementNode *l, int e, Node *n)      : list(l->list), elision(e), node(n) { l->list = this; }    virtual void ref();    virtual bool deref();    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    friend class ArrayNode;    ElementNode *list;    int elision;    Node *node;  };  class ArrayNode : public Node {  public:    ArrayNode(int e) : element(0L), elision(e), opt(true) { }    ArrayNode(ElementNode *ele)      : element(ele->list), elision(0), opt(false) { ele->list = 0; }    ArrayNode(int eli, ElementNode *ele)      : element(ele->list), elision(eli), opt(true) { ele->list = 0; }    virtual void ref();    virtual bool deref();    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    ElementNode *element;    int elision;    bool opt;  };  class PropertyValueNode : public Node {  public:    // list is circular during construction, cut in ObjectLiteralNode ctor    PropertyValueNode(PropertyNode *n, Node *a)      : name(n), assign(a), list(this) { }    PropertyValueNode(PropertyNode *n, Node *a, PropertyValueNode *l)      : name(n), assign(a), list(l->list) { l->list = this; }    virtual void ref();    virtual bool deref();    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    friend class ObjectLiteralNode;    PropertyNode *name;    Node *assign;    PropertyValueNode *list;  };  class PropertyNode : public Node {  public:    PropertyNode(double d) : numeric(d) { }    PropertyNode(const Identifier &s) : str(s) { }    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    double numeric;    Identifier str;  };  class ObjectLiteralNode : public Node {  public:    // empty literal    ObjectLiteralNode() : list(0) { }    // l points to last list element, get and detach pointer to first one    ObjectLiteralNode(PropertyValueNode *l) : list(l->list) { l->list = 0; }    virtual void ref();    virtual bool deref();    virtual Value evaluate(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    PropertyValueNode *list;  };  class AccessorNode1 : public Node {  public:    AccessorNode1(Node *e1, Node *e2) : expr1(e1), expr2(e2) {}    virtual void ref();    virtual bool deref();    Reference evaluateReference(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    Node *expr1;    Node *expr2;  };  class AccessorNode2 : public Node {  public:    AccessorNode2(Node *e, const Identifier &s) : expr(e), ident(s) { }    virtual void ref();    virtual bool deref();    Reference evaluateReference(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    Node *expr;    Identifier ident;  };  class ArgumentListNode : public Node {  public:    // list is circular during construction. cracked in ArgumentsNode ctor    ArgumentListNode(Node *e) : list(this), expr(e) {}    ArgumentListNode(ArgumentListNode *l, Node *e)      : list(l->list), expr(e) { l->list = this; }    virtual void ref();    virtual bool deref();    virtual Value evaluate(ExecState *exec) const;    List evaluateList(ExecState *exec) const;    virtual void streamTo(SourceStream &s) const;  private:    friend class ArgumentsNode;    ArgumentListNode *list;    Node *expr;  };

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?