⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ast.h.svn-base

📁 Google浏览器V8内核代码
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
// Copyright 2006-2008 the V8 project authors. All rights reserved.// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met:////     * Redistributions of source code must retain the above copyright//       notice, this list of conditions and the following disclaimer.//     * Redistributions in binary form must reproduce the above//       copyright notice, this list of conditions and the following//       disclaimer in the documentation and/or other materials provided//       with the distribution.//     * Neither the name of Google Inc. nor the names of its//       contributors may be used to endorse or promote products derived//       from this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#ifndef V8_AST_H_#define V8_AST_H_#include "execution.h"#include "factory.h"#include "runtime.h"#include "token.h"#include "variables.h"#include "macro-assembler.h"namespace v8 { namespace internal {// The abstract syntax tree is an intermediate, light-weight// representation of the parsed JavaScript code suitable for// compilation to native code.// Nodes are allocated in a separate zone, which allows faster// allocation and constant-time deallocation of the entire syntax// tree.// ----------------------------------------------------------------------------// Nodes of the abstract syntax tree. Only concrete classes are// enumerated here.#define NODE_LIST(V)                            \  V(Block)                                      \  V(Declaration)                                \  V(ExpressionStatement)                        \  V(EmptyStatement)                             \  V(IfStatement)                                \  V(ContinueStatement)                          \  V(BreakStatement)                             \  V(ReturnStatement)                            \  V(WithEnterStatement)                         \  V(WithExitStatement)                          \  V(SwitchStatement)                            \  V(LoopStatement)                              \  V(ForInStatement)                             \  V(TryCatch)                                   \  V(TryFinally)                                 \  V(DebuggerStatement)                          \  V(FunctionLiteral)                            \  V(FunctionBoilerplateLiteral)                 \  V(Conditional)                                \  V(Slot)                                       \  V(VariableProxy)                              \  V(Literal)                                    \  V(RegExpLiteral)                              \  V(ObjectLiteral)                              \  V(ArrayLiteral)                               \  V(Assignment)                                 \  V(Throw)                                      \  V(Property)                                   \  V(Call)                                       \  V(CallNew)                                    \  V(CallRuntime)                                \  V(UnaryOperation)                             \  V(CountOperation)                             \  V(BinaryOperation)                            \  V(CompareOperation)                           \  V(ThisFunction)#define DEF_FORWARD_DECLARATION(type) class type;NODE_LIST(DEF_FORWARD_DECLARATION)#undef DEF_FORWARD_DECLARATION// Typedef only introduced to avoid unreadable code.// Please do appreciate the required space in "> >".typedef ZoneList<Handle<String> > ZoneStringList;class Node: public ZoneObject { public:  Node(): statement_pos_(RelocInfo::kNoPosition) { }  virtual ~Node() { }  virtual void Accept(Visitor* v) = 0;  // Type testing & conversion.  virtual Statement* AsStatement() { return NULL; }  virtual ExpressionStatement* AsExpressionStatement() { return NULL; }  virtual EmptyStatement* AsEmptyStatement() { return NULL; }  virtual Expression* AsExpression() { return NULL; }  virtual Literal* AsLiteral() { return NULL; }  virtual Slot* AsSlot() { return NULL; }  virtual VariableProxy* AsVariableProxy() { return NULL; }  virtual Property* AsProperty() { return NULL; }  virtual Call* AsCall() { return NULL; }  virtual LabelCollector* AsLabelCollector() { return NULL; }  virtual BreakableStatement* AsBreakableStatement() { return NULL; }  virtual IterationStatement* AsIterationStatement() { return NULL; }  virtual UnaryOperation* AsUnaryOperation() { return NULL; }  virtual BinaryOperation* AsBinaryOperation() { return NULL; }  virtual Assignment* AsAssignment() { return NULL; }  virtual FunctionLiteral* AsFunctionLiteral() { return NULL; }  void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }  int statement_pos() const { return statement_pos_; } private:  int statement_pos_;};class Statement: public Node { public:  virtual Statement* AsStatement()  { return this; }  virtual ReturnStatement* AsReturnStatement() { return NULL; }  bool IsEmpty() { return AsEmptyStatement() != NULL; }};class Reference;enum InitState { CONST_INIT, NOT_CONST_INIT };class Expression: public Node { public:  virtual Expression* AsExpression()  { return this; }  virtual bool IsValidLeftHandSide() { return false; }  // Mark the expression as being compiled as an expression  // statement. This is used to transform postfix increments to  // (faster) prefix increments.  virtual void MarkAsStatement() { /* do nothing */ }  // Generate code to store into an expression evaluated as the left-hand  // side of an assignment.  The code will expect the stored value on top of  // the expression stack, and a reference containing the expression  // immediately below that.  This function is overridden for expression  // types that can be stored into.  virtual void GenerateStoreCode(MacroAssembler* masm,                                 Scope* scope,                                 Reference* ref,                                 InitState init_state) {    UNREACHABLE();  }};/** * A sentinel used during pre parsing that represents some expression * that is a valid left hand side without having to actually build * the expression. */class ValidLeftHandSideSentinel: public Expression { public:  virtual bool IsValidLeftHandSide() { return true; }  virtual void Accept(Visitor* v) { UNREACHABLE(); }  static ValidLeftHandSideSentinel* instance() { return &instance_; } private:  static ValidLeftHandSideSentinel instance_;};class BreakableStatement: public Statement { public:  enum Type {    TARGET_FOR_ANONYMOUS,    TARGET_FOR_NAMED_ONLY  };  // The labels associated with this statement. May be NULL;  // if it is != NULL, guaranteed to contain at least one entry.  ZoneStringList* labels() const { return labels_; }  // Type testing & conversion.  virtual BreakableStatement* AsBreakableStatement() { return this; }  // Code generation  Label* break_target() { return &break_target_; }  // Used during code generation for restoring the stack when a  // break/continue crosses a statement that keeps stuff on the stack.  int break_stack_height() { return break_stack_height_; }  void set_break_stack_height(int height) { break_stack_height_ = height; }  // Testers.  bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } protected:  BreakableStatement(ZoneStringList* labels, Type type)      : labels_(labels), type_(type) {    ASSERT(labels == NULL || labels->length() > 0);  } private:  ZoneStringList* labels_;  Type type_;  Label break_target_;  int break_stack_height_;};class Block: public BreakableStatement { public:  Block(ZoneStringList* labels, int capacity, bool is_initializer_block)      : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY),        statements_(capacity),        is_initializer_block_(is_initializer_block) { }  virtual void Accept(Visitor* v);  void AddStatement(Statement* statement) { statements_.Add(statement); }  ZoneList<Statement*>* statements() { return &statements_; }  bool is_initializer_block() const  { return is_initializer_block_; } private:  ZoneList<Statement*> statements_;  bool is_initializer_block_;};class Declaration: public Node { public:  Declaration(VariableProxy* proxy, Variable::Mode mode, FunctionLiteral* fun)    : proxy_(proxy),      mode_(mode),      fun_(fun) {    ASSERT(mode == Variable::VAR || mode == Variable::CONST);    // At the moment there are no "const functions"'s in JavaScript...    ASSERT(fun == NULL || mode == Variable::VAR);  }  virtual void Accept(Visitor* v);  VariableProxy* proxy() const  { return proxy_; }  Variable::Mode mode() const  { return mode_; }  FunctionLiteral* fun() const  { return fun_; }  // may be NULL private:  VariableProxy* proxy_;  Variable::Mode mode_;  FunctionLiteral* fun_;};class IterationStatement: public BreakableStatement { public:  // Type testing & conversion.  virtual IterationStatement* AsIterationStatement() { return this; }  Statement* body() const { return body_; }  // Code generation  Label* continue_target()  { return &continue_target_; } protected:  explicit IterationStatement(ZoneStringList* labels)    : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { }  void Initialize(Statement* body) {    body_ = body;  } private:  Statement* body_;  Label continue_target_;};class LoopStatement: public IterationStatement { public:  enum Type { DO_LOOP, FOR_LOOP, WHILE_LOOP };  LoopStatement(ZoneStringList* labels, Type type)      : IterationStatement(labels), type_(type), init_(NULL),        cond_(NULL), next_(NULL) { }  void Initialize(Statement* init,                  Expression* cond,                  Statement* next,                  Statement* body) {    ASSERT(init == NULL || type_ == FOR_LOOP);    ASSERT(next == NULL || type_ == FOR_LOOP);    IterationStatement::Initialize(body);    init_ = init;    cond_ = cond;    next_ = next;  }  virtual void Accept(Visitor* v);  Type type() const  { return type_; }  Statement* init() const  { return init_; }  Expression* cond() const  { return cond_; }  Statement* next() const  { return next_; }#ifdef DEBUG  const char* OperatorString() const;#endif private:  Type type_;  Statement* init_;  Expression* cond_;  Statement* next_;};class ForInStatement: public IterationStatement { public:  explicit ForInStatement(ZoneStringList* labels)    : IterationStatement(labels), each_(NULL), enumerable_(NULL) { }  void Initialize(Expression* each, Expression* enumerable, Statement* body) {    IterationStatement::Initialize(body);    each_ = each;    enumerable_ = enumerable;  }  virtual void Accept(Visitor* v);  Expression* each() const { return each_; }  Expression* enumerable() const { return enumerable_; } private:  Expression* each_;  Expression* enumerable_;};class ExpressionStatement: public Statement { public:  explicit ExpressionStatement(Expression* expression)      : expression_(expression) { }  virtual void Accept(Visitor* v);  // Type testing & conversion.  virtual ExpressionStatement* AsExpressionStatement() { return this; }  void set_expression(Expression* e) { expression_ = e; }  Expression* expression() { return expression_; } private:  Expression* expression_;};class ContinueStatement: public Statement { public:  explicit ContinueStatement(IterationStatement* target)      : target_(target) { }  virtual void Accept(Visitor* v);  IterationStatement* target() const  { return target_; } private:  IterationStatement* target_;};class BreakStatement: public Statement { public:  explicit BreakStatement(BreakableStatement* target)      : target_(target) { }  virtual void Accept(Visitor* v);  BreakableStatement* target() const  { return target_; } private:  BreakableStatement* target_;};class ReturnStatement: public Statement { public:  explicit ReturnStatement(Expression* expression)      : expression_(expression) { }  virtual void Accept(Visitor* v);  // Type testing & conversion.  virtual ReturnStatement* AsReturnStatement() { return this; }  Expression* expression() { return expression_; } private:  Expression* expression_;};class WithEnterStatement: public Statement { public:  explicit WithEnterStatement(Expression* expression)      : expression_(expression) { }  virtual void Accept(Visitor* v);  Expression* expression() const  { return expression_; } private:

⌨️ 快捷键说明

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