LCOV - code coverage report
Current view: top level - src/ast - ast.h (source / functions) Hit Total Coverage
Test: app.info Lines: 353 406 86.9 %
Date: 2017-10-20 Functions: 101 112 90.2 %

          Line data    Source code
       1             : // Copyright 2012 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_AST_AST_H_
       6             : #define V8_AST_AST_H_
       7             : 
       8             : #include "src/ast/ast-value-factory.h"
       9             : #include "src/ast/modules.h"
      10             : #include "src/ast/variables.h"
      11             : #include "src/bailout-reason.h"
      12             : #include "src/factory.h"
      13             : #include "src/globals.h"
      14             : #include "src/isolate.h"
      15             : #include "src/label.h"
      16             : #include "src/objects/literal-objects.h"
      17             : #include "src/parsing/token.h"
      18             : #include "src/runtime/runtime.h"
      19             : 
      20             : namespace v8 {
      21             : namespace internal {
      22             : 
      23             : // The abstract syntax tree is an intermediate, light-weight
      24             : // representation of the parsed JavaScript code suitable for
      25             : // compilation to native code.
      26             : 
      27             : // Nodes are allocated in a separate zone, which allows faster
      28             : // allocation and constant-time deallocation of the entire syntax
      29             : // tree.
      30             : 
      31             : 
      32             : // ----------------------------------------------------------------------------
      33             : // Nodes of the abstract syntax tree. Only concrete classes are
      34             : // enumerated here.
      35             : 
      36             : #define DECLARATION_NODE_LIST(V) \
      37             :   V(VariableDeclaration)         \
      38             :   V(FunctionDeclaration)
      39             : 
      40             : #define ITERATION_NODE_LIST(V) \
      41             :   V(DoWhileStatement)          \
      42             :   V(WhileStatement)            \
      43             :   V(ForStatement)              \
      44             :   V(ForInStatement)            \
      45             :   V(ForOfStatement)
      46             : 
      47             : #define BREAKABLE_NODE_LIST(V) \
      48             :   V(Block)                     \
      49             :   V(SwitchStatement)
      50             : 
      51             : #define STATEMENT_NODE_LIST(V)    \
      52             :   ITERATION_NODE_LIST(V)          \
      53             :   BREAKABLE_NODE_LIST(V)          \
      54             :   V(ExpressionStatement)          \
      55             :   V(EmptyStatement)               \
      56             :   V(SloppyBlockFunctionStatement) \
      57             :   V(IfStatement)                  \
      58             :   V(ContinueStatement)            \
      59             :   V(BreakStatement)               \
      60             :   V(ReturnStatement)              \
      61             :   V(WithStatement)                \
      62             :   V(TryCatchStatement)            \
      63             :   V(TryFinallyStatement)          \
      64             :   V(DebuggerStatement)
      65             : 
      66             : #define LITERAL_NODE_LIST(V) \
      67             :   V(RegExpLiteral)           \
      68             :   V(ObjectLiteral)           \
      69             :   V(ArrayLiteral)
      70             : 
      71             : #define EXPRESSION_NODE_LIST(V) \
      72             :   LITERAL_NODE_LIST(V)          \
      73             :   V(Assignment)                 \
      74             :   V(Await)                      \
      75             :   V(BinaryOperation)            \
      76             :   V(Call)                       \
      77             :   V(CallNew)                    \
      78             :   V(CallRuntime)                \
      79             :   V(ClassLiteral)               \
      80             :   V(CompareOperation)           \
      81             :   V(CompoundAssignment)         \
      82             :   V(Conditional)                \
      83             :   V(CountOperation)             \
      84             :   V(DoExpression)               \
      85             :   V(EmptyParentheses)           \
      86             :   V(FunctionLiteral)            \
      87             :   V(GetIterator)                \
      88             :   V(GetTemplateObject)          \
      89             :   V(ImportCallExpression)       \
      90             :   V(Literal)                    \
      91             :   V(NativeFunctionLiteral)      \
      92             :   V(Property)                   \
      93             :   V(RewritableExpression)       \
      94             :   V(Spread)                     \
      95             :   V(SuperCallReference)         \
      96             :   V(SuperPropertyReference)     \
      97             :   V(ThisFunction)               \
      98             :   V(Throw)                      \
      99             :   V(UnaryOperation)             \
     100             :   V(VariableProxy)              \
     101             :   V(Yield)                      \
     102             :   V(YieldStar)
     103             : 
     104             : #define AST_NODE_LIST(V)                        \
     105             :   DECLARATION_NODE_LIST(V)                      \
     106             :   STATEMENT_NODE_LIST(V)                        \
     107             :   EXPRESSION_NODE_LIST(V)
     108             : 
     109             : // Forward declarations
     110             : class AstNode;
     111             : class AstNodeFactory;
     112             : class Declaration;
     113             : class BreakableStatement;
     114             : class Expression;
     115             : class IterationStatement;
     116             : class MaterializedLiteral;
     117             : class NestedVariableDeclaration;
     118             : class ProducedPreParsedScopeData;
     119             : class Statement;
     120             : 
     121             : #define DEF_FORWARD_DECLARATION(type) class type;
     122             : AST_NODE_LIST(DEF_FORWARD_DECLARATION)
     123             : #undef DEF_FORWARD_DECLARATION
     124             : 
     125             : class AstNode: public ZoneObject {
     126             :  public:
     127             : #define DECLARE_TYPE_ENUM(type) k##type,
     128             :   enum NodeType : uint8_t { AST_NODE_LIST(DECLARE_TYPE_ENUM) };
     129             : #undef DECLARE_TYPE_ENUM
     130             : 
     131   285201534 :   void* operator new(size_t size, Zone* zone) { return zone->New(size); }
     132             : 
     133  1601144836 :   NodeType node_type() const { return NodeTypeField::decode(bit_field_); }
     134       59281 :   int position() const { return position_; }
     135             : 
     136             : #ifdef DEBUG
     137             :   void Print();
     138             :   void Print(Isolate* isolate);
     139             : #endif  // DEBUG
     140             : 
     141             :   // Type testing & conversion functions overridden by concrete subclasses.
     142             : #define DECLARE_NODE_FUNCTIONS(type) \
     143             :   V8_INLINE bool Is##type() const;   \
     144             :   V8_INLINE type* As##type();        \
     145             :   V8_INLINE const type* As##type() const;
     146             :   AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
     147             : #undef DECLARE_NODE_FUNCTIONS
     148             : 
     149             :   BreakableStatement* AsBreakableStatement();
     150             :   IterationStatement* AsIterationStatement();
     151             :   MaterializedLiteral* AsMaterializedLiteral();
     152             : 
     153             :  private:
     154             :   // Hidden to prevent accidental usage. It would have to load the
     155             :   // current zone from the TLS.
     156             :   void* operator new(size_t size);
     157             : 
     158             :   int position_;
     159             :   class NodeTypeField : public BitField<NodeType, 0, 6> {};
     160             : 
     161             :  protected:
     162             :   uint32_t bit_field_;
     163             :   static const uint8_t kNextBitFieldIndex = NodeTypeField::kNext;
     164             : 
     165             :   AstNode(int position, NodeType type)
     166   302354263 :       : position_(position), bit_field_(NodeTypeField::encode(type)) {}
     167             : };
     168             : 
     169             : 
     170             : class Statement : public AstNode {
     171             :  public:
     172    10007660 :   bool IsEmpty() { return AsEmptyStatement() != nullptr; }
     173             :   bool IsJump() const;
     174             : 
     175             :  protected:
     176             :   Statement(int position, NodeType type) : AstNode(position, type) {}
     177             : 
     178             :   static const uint8_t kNextBitFieldIndex = AstNode::kNextBitFieldIndex;
     179             : };
     180             : 
     181             : 
     182             : class Expression : public AstNode {
     183             :  public:
     184             :   enum Context {
     185             :     // Not assigned a context yet, or else will not be visited during
     186             :     // code generation.
     187             :     kUninitialized,
     188             :     // Evaluated for its side effects.
     189             :     kEffect,
     190             :     // Evaluated for its value (and side effects).
     191             :     kValue,
     192             :     // Evaluated for control flow (and side effects).
     193             :     kTest
     194             :   };
     195             : 
     196             :   // True iff the expression is a valid reference expression.
     197             :   bool IsValidReferenceExpression() const;
     198             : 
     199             :   // Helpers for ToBoolean conversion.
     200             :   bool ToBooleanIsTrue() const;
     201             :   bool ToBooleanIsFalse() const;
     202             : 
     203             :   // Symbols that cannot be parsed as array indices are considered property
     204             :   // names.  We do not treat symbols that can be array indexes as property
     205             :   // names because [] for string objects is handled only by keyed ICs.
     206             :   bool IsPropertyName() const;
     207             : 
     208             :   // True iff the expression is a class or function expression without
     209             :   // a syntactic name.
     210             :   bool IsAnonymousFunctionDefinition() const;
     211             : 
     212             :   // True iff the expression is a concise method definition.
     213             :   bool IsConciseMethodDefinition() const;
     214             : 
     215             :   // True iff the expression is an accessor function definition.
     216             :   bool IsAccessorFunctionDefinition() const;
     217             : 
     218             :   // True iff the expression is a literal represented as a smi.
     219             :   bool IsSmiLiteral() const;
     220             : 
     221             :   // True iff the expression is a literal represented as a number.
     222             :   bool IsNumberLiteral() const;
     223             : 
     224             :   // True iff the expression is a string literal.
     225             :   bool IsStringLiteral() const;
     226             : 
     227             :   // True iff the expression is the null literal.
     228             :   bool IsNullLiteral() const;
     229             : 
     230             :   // True if we can prove that the expression is the undefined literal. Note
     231             :   // that this also checks for loads of the global "undefined" variable.
     232             :   bool IsUndefinedLiteral() const;
     233             : 
     234             :  protected:
     235             :   Expression(int pos, NodeType type) : AstNode(pos, type) {}
     236             : 
     237             :   static const uint8_t kNextBitFieldIndex = AstNode::kNextBitFieldIndex;
     238             : };
     239             : 
     240             : 
     241             : class BreakableStatement : public Statement {
     242             :  public:
     243             :   enum BreakableType {
     244             :     TARGET_FOR_ANONYMOUS,
     245             :     TARGET_FOR_NAMED_ONLY
     246             :   };
     247             : 
     248             :   ZoneList<const AstRawString*>* labels() const;
     249             : 
     250             :   // Testers.
     251             :   bool is_target_for_anonymous() const {
     252             :     return BreakableTypeField::decode(bit_field_) == TARGET_FOR_ANONYMOUS;
     253             :   }
     254             : 
     255             :  private:
     256             :   class BreakableTypeField
     257             :       : public BitField<BreakableType, Statement::kNextBitFieldIndex, 1> {};
     258             : 
     259             :  protected:
     260             :   BreakableStatement(BreakableType breakable_type, int position, NodeType type)
     261             :       : Statement(position, type) {
     262    14189391 :     bit_field_ |= BreakableTypeField::encode(breakable_type);
     263             :   }
     264             : 
     265             :   static const uint8_t kNextBitFieldIndex = BreakableTypeField::kNext;
     266             : };
     267             : 
     268             : class Block : public BreakableStatement {
     269             :  public:
     270      491719 :   ZoneList<Statement*>* statements() { return &statements_; }
     271             :   bool ignore_completion_value() const {
     272             :     return IgnoreCompletionField::decode(bit_field_);
     273             :   }
     274             : 
     275             :   inline ZoneList<const AstRawString*>* labels() const;
     276             : 
     277     9257676 :   bool IsJump() const {
     278    15981204 :     return !statements_.is_empty() && statements_.last()->IsJump() &&
     279     9257676 :            labels() == nullptr;  // Good enough as an approximation...
     280             :   }
     281             : 
     282             :   Scope* scope() const { return scope_; }
     283     2782755 :   void set_scope(Scope* scope) { scope_ = scope; }
     284             : 
     285             :  private:
     286             :   friend class AstNodeFactory;
     287             : 
     288             :   ZoneList<Statement*> statements_;
     289             :   Scope* scope_;
     290             : 
     291             :   class IgnoreCompletionField
     292             :       : public BitField<bool, BreakableStatement::kNextBitFieldIndex, 1> {};
     293             :   class IsLabeledField
     294             :       : public BitField<bool, IgnoreCompletionField::kNext, 1> {};
     295             : 
     296             :  protected:
     297    14189391 :   Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
     298             :         bool ignore_completion_value)
     299             :       : BreakableStatement(TARGET_FOR_NAMED_ONLY, kNoSourcePosition, kBlock),
     300             :         statements_(capacity, zone),
     301    14189391 :         scope_(nullptr) {
     302             :     bit_field_ |= IgnoreCompletionField::encode(ignore_completion_value) |
     303    28378772 :                   IsLabeledField::encode(labels != nullptr);
     304    14189386 :   }
     305             : };
     306             : 
     307             : class LabeledBlock final : public Block {
     308             :  private:
     309             :   friend class AstNodeFactory;
     310             :   friend class Block;
     311             : 
     312             :   LabeledBlock(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
     313             :                bool ignore_completion_value)
     314             :       : Block(zone, labels, capacity, ignore_completion_value),
     315        6470 :         labels_(labels) {
     316             :     DCHECK_NOT_NULL(labels);
     317             :     DCHECK_GT(labels->length(), 0);
     318             :   }
     319             : 
     320             :   ZoneList<const AstRawString*>* labels_;
     321             : };
     322             : 
     323             : inline ZoneList<const AstRawString*>* Block::labels() const {
     324      903032 :   if (IsLabeledField::decode(bit_field_)) {
     325        6914 :     return static_cast<const LabeledBlock*>(this)->labels_;
     326             :   }
     327             :   return nullptr;
     328             : }
     329             : 
     330             : class DoExpression final : public Expression {
     331             :  public:
     332             :   Block* block() { return block_; }
     333           0 :   void set_block(Block* b) { block_ = b; }
     334             :   VariableProxy* result() { return result_; }
     335           0 :   void set_result(VariableProxy* v) { result_ = v; }
     336             : 
     337             :  private:
     338             :   friend class AstNodeFactory;
     339             : 
     340             :   DoExpression(Block* block, VariableProxy* result, int pos)
     341       80510 :       : Expression(pos, kDoExpression), block_(block), result_(result) {
     342             :     DCHECK_NOT_NULL(block_);
     343             :     DCHECK_NOT_NULL(result_);
     344             :   }
     345             : 
     346             :   Block* block_;
     347             :   VariableProxy* result_;
     348             : };
     349             : 
     350             : 
     351             : class Declaration : public AstNode {
     352             :  public:
     353             :   typedef ThreadedList<Declaration> List;
     354             : 
     355      149674 :   VariableProxy* proxy() const { return proxy_; }
     356             : 
     357             :  protected:
     358             :   Declaration(VariableProxy* proxy, int pos, NodeType type)
     359    10708737 :       : AstNode(pos, type), proxy_(proxy), next_(nullptr) {}
     360             : 
     361             :  private:
     362             :   VariableProxy* proxy_;
     363             :   // Declarations list threaded through the declarations.
     364             :   Declaration** next() { return &next_; }
     365             :   Declaration* next_;
     366             :   friend List;
     367             : };
     368             : 
     369             : class VariableDeclaration : public Declaration {
     370             :  public:
     371             :   inline NestedVariableDeclaration* AsNested();
     372             : 
     373             :  private:
     374             :   friend class AstNodeFactory;
     375             : 
     376             :   class IsNestedField
     377             :       : public BitField<bool, Declaration::kNextBitFieldIndex, 1> {};
     378             : 
     379             :  protected:
     380             :   VariableDeclaration(VariableProxy* proxy, int pos, bool is_nested = false)
     381             :       : Declaration(proxy, pos, kVariableDeclaration) {
     382      797235 :     bit_field_ = IsNestedField::update(bit_field_, is_nested);
     383             :   }
     384             : 
     385             :   static const uint8_t kNextBitFieldIndex = IsNestedField::kNext;
     386             : };
     387             : 
     388             : // For var declarations that appear in a block scope.
     389             : // Only distinguished from VariableDeclaration during Scope analysis,
     390             : // so it doesn't get its own NodeType.
     391             : class NestedVariableDeclaration final : public VariableDeclaration {
     392             :  public:
     393             :   Scope* scope() const { return scope_; }
     394             : 
     395             :  private:
     396             :   friend class AstNodeFactory;
     397             : 
     398             :   NestedVariableDeclaration(VariableProxy* proxy, Scope* scope, int pos)
     399      797235 :       : VariableDeclaration(proxy, pos, true), scope_(scope) {}
     400             : 
     401             :   // Nested scope from which the declaration originated.
     402             :   Scope* scope_;
     403             : };
     404             : 
     405             : inline NestedVariableDeclaration* VariableDeclaration::AsNested() {
     406     9629422 :   return IsNestedField::decode(bit_field_)
     407             :              ? static_cast<NestedVariableDeclaration*>(this)
     408     9629422 :              : nullptr;
     409             : }
     410             : 
     411             : class FunctionDeclaration final : public Declaration {
     412             :  public:
     413             :   FunctionLiteral* fun() const { return fun_; }
     414           0 :   void set_fun(FunctionLiteral* f) { fun_ = f; }
     415             : 
     416             :  private:
     417             :   friend class AstNodeFactory;
     418             : 
     419             :   FunctionDeclaration(VariableProxy* proxy, FunctionLiteral* fun, int pos)
     420     1219128 :       : Declaration(proxy, pos, kFunctionDeclaration), fun_(fun) {
     421             :     DCHECK_NOT_NULL(fun);
     422             :   }
     423             : 
     424             :   FunctionLiteral* fun_;
     425             : };
     426             : 
     427             : 
     428             : class IterationStatement : public BreakableStatement {
     429             :  public:
     430             :   Statement* body() const { return body_; }
     431       55558 :   void set_body(Statement* s) { body_ = s; }
     432             : 
     433             :   ZoneList<const AstRawString*>* labels() const { return labels_; }
     434             : 
     435             :   int suspend_count() const { return suspend_count_; }
     436             :   int first_suspend_id() const { return first_suspend_id_; }
     437      243370 :   void set_suspend_count(int suspend_count) { suspend_count_ = suspend_count; }
     438             :   void set_first_suspend_id(int first_suspend_id) {
     439      243370 :     first_suspend_id_ = first_suspend_id;
     440             :   }
     441             : 
     442             :  protected:
     443             :   IterationStatement(ZoneList<const AstRawString*>* labels, int pos,
     444             :                      NodeType type)
     445             :       : BreakableStatement(TARGET_FOR_ANONYMOUS, pos, type),
     446             :         labels_(labels),
     447             :         body_(nullptr),
     448             :         suspend_count_(0),
     449      707694 :         first_suspend_id_(0) {}
     450      682738 :   void Initialize(Statement* body) { body_ = body; }
     451             : 
     452             :   static const uint8_t kNextBitFieldIndex =
     453             :       BreakableStatement::kNextBitFieldIndex;
     454             : 
     455             :  private:
     456             :   ZoneList<const AstRawString*>* labels_;
     457             :   Statement* body_;
     458             :   int suspend_count_;
     459             :   int first_suspend_id_;
     460             : };
     461             : 
     462             : 
     463             : class DoWhileStatement final : public IterationStatement {
     464             :  public:
     465             :   void Initialize(Expression* cond, Statement* body) {
     466             :     IterationStatement::Initialize(body);
     467        5582 :     cond_ = cond;
     468             :   }
     469             : 
     470             :   Expression* cond() const { return cond_; }
     471           0 :   void set_cond(Expression* e) { cond_ = e; }
     472             : 
     473             :  private:
     474             :   friend class AstNodeFactory;
     475             : 
     476             :   DoWhileStatement(ZoneList<const AstRawString*>* labels, int pos)
     477        6827 :       : IterationStatement(labels, pos, kDoWhileStatement), cond_(nullptr) {}
     478             : 
     479             :   Expression* cond_;
     480             : };
     481             : 
     482             : 
     483             : class WhileStatement final : public IterationStatement {
     484             :  public:
     485             :   void Initialize(Expression* cond, Statement* body) {
     486             :     IterationStatement::Initialize(body);
     487       68782 :     cond_ = cond;
     488             :   }
     489             : 
     490             :   Expression* cond() const { return cond_; }
     491           0 :   void set_cond(Expression* e) { cond_ = e; }
     492             : 
     493             :  private:
     494             :   friend class AstNodeFactory;
     495             : 
     496             :   WhileStatement(ZoneList<const AstRawString*>* labels, int pos)
     497       69923 :       : IterationStatement(labels, pos, kWhileStatement), cond_(nullptr) {}
     498             : 
     499             :   Expression* cond_;
     500             : };
     501             : 
     502             : 
     503             : class ForStatement final : public IterationStatement {
     504             :  public:
     505             :   void Initialize(Statement* init, Expression* cond, Statement* next,
     506             :                   Statement* body) {
     507             :     IterationStatement::Initialize(body);
     508      457400 :     init_ = init;
     509      457400 :     cond_ = cond;
     510      457400 :     next_ = next;
     511             :   }
     512             : 
     513             :   Statement* init() const { return init_; }
     514             :   Expression* cond() const { return cond_; }
     515             :   Statement* next() const { return next_; }
     516             : 
     517           0 :   void set_init(Statement* s) { init_ = s; }
     518           0 :   void set_cond(Expression* e) { cond_ = e; }
     519           0 :   void set_next(Statement* s) { next_ = s; }
     520             : 
     521             :  private:
     522             :   friend class AstNodeFactory;
     523             : 
     524             :   ForStatement(ZoneList<const AstRawString*>* labels, int pos)
     525             :       : IterationStatement(labels, pos, kForStatement),
     526             :         init_(nullptr),
     527             :         cond_(nullptr),
     528      458913 :         next_(nullptr) {}
     529             : 
     530             :   Statement* init_;
     531             :   Expression* cond_;
     532             :   Statement* next_;
     533             : };
     534             : 
     535             : 
     536             : class ForEachStatement : public IterationStatement {
     537             :  public:
     538             :   enum VisitMode {
     539             :     ENUMERATE,   // for (each in subject) body;
     540             :     ITERATE      // for (each of subject) body;
     541             :   };
     542             : 
     543             :   using IterationStatement::Initialize;
     544             : 
     545             :   static const char* VisitModeString(VisitMode mode) {
     546        6552 :     return mode == ITERATE ? "for-of" : "for-in";
     547             :   }
     548             : 
     549             :  protected:
     550             :   ForEachStatement(ZoneList<const AstRawString*>* labels, int pos,
     551             :                    NodeType type)
     552             :       : IterationStatement(labels, pos, type) {}
     553             : };
     554             : 
     555             : 
     556             : class ForInStatement final : public ForEachStatement {
     557             :  public:
     558             :   void Initialize(Expression* each, Expression* subject, Statement* body) {
     559             :     ForEachStatement::Initialize(body);
     560       47742 :     each_ = each;
     561       47742 :     subject_ = subject;
     562             :   }
     563             : 
     564        7691 :   Expression* enumerable() const {
     565             :     return subject();
     566             :   }
     567             : 
     568             :   Expression* each() const { return each_; }
     569             :   Expression* subject() const { return subject_; }
     570             : 
     571           0 :   void set_each(Expression* e) { each_ = e; }
     572           0 :   void set_subject(Expression* e) { subject_ = e; }
     573             : 
     574             :   enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
     575             :   ForInType for_in_type() const { return ForInTypeField::decode(bit_field_); }
     576             :   void set_for_in_type(ForInType type) {
     577             :     bit_field_ = ForInTypeField::update(bit_field_, type);
     578             :   }
     579             : 
     580             :  private:
     581             :   friend class AstNodeFactory;
     582             : 
     583             :   ForInStatement(ZoneList<const AstRawString*>* labels, int pos)
     584             :       : ForEachStatement(labels, pos, kForInStatement),
     585             :         each_(nullptr),
     586       53682 :         subject_(nullptr) {
     587       53682 :     bit_field_ = ForInTypeField::update(bit_field_, SLOW_FOR_IN);
     588             :   }
     589             : 
     590             :   Expression* each_;
     591             :   Expression* subject_;
     592             : 
     593             :   class ForInTypeField
     594             :       : public BitField<ForInType, ForEachStatement::kNextBitFieldIndex, 1> {};
     595             : };
     596             : 
     597             : 
     598             : class ForOfStatement final : public ForEachStatement {
     599             :  public:
     600             :   void Initialize(Statement* body, Variable* iterator,
     601             :                   Expression* assign_iterator, Expression* next_result,
     602             :                   Expression* result_done, Expression* assign_each) {
     603             :     ForEachStatement::Initialize(body);
     604      103232 :     iterator_ = iterator;
     605      103232 :     assign_iterator_ = assign_iterator;
     606      103232 :     next_result_ = next_result;
     607      103232 :     result_done_ = result_done;
     608      103232 :     assign_each_ = assign_each;
     609             :   }
     610             : 
     611             :   Variable* iterator() const {
     612             :     return iterator_;
     613             :   }
     614             : 
     615             :   // iterator = subject[Symbol.iterator]()
     616             :   Expression* assign_iterator() const {
     617             :     return assign_iterator_;
     618             :   }
     619             : 
     620             :   // result = iterator.next()  // with type check
     621             :   Expression* next_result() const {
     622             :     return next_result_;
     623             :   }
     624             : 
     625             :   // result.done
     626             :   Expression* result_done() const {
     627             :     return result_done_;
     628             :   }
     629             : 
     630             :   // each = result.value
     631             :   Expression* assign_each() const {
     632             :     return assign_each_;
     633             :   }
     634             : 
     635           0 :   void set_assign_iterator(Expression* e) { assign_iterator_ = e; }
     636           0 :   void set_next_result(Expression* e) { next_result_ = e; }
     637           0 :   void set_result_done(Expression* e) { result_done_ = e; }
     638           0 :   void set_assign_each(Expression* e) { assign_each_ = e; }
     639             : 
     640             :  private:
     641             :   friend class AstNodeFactory;
     642             : 
     643             :   ForOfStatement(ZoneList<const AstRawString*>* labels, int pos)
     644             :       : ForEachStatement(labels, pos, kForOfStatement),
     645             :         iterator_(nullptr),
     646             :         assign_iterator_(nullptr),
     647             :         next_result_(nullptr),
     648             :         result_done_(nullptr),
     649      118349 :         assign_each_(nullptr) {}
     650             : 
     651             :   Variable* iterator_;
     652             :   Expression* assign_iterator_;
     653             :   Expression* next_result_;
     654             :   Expression* result_done_;
     655             :   Expression* assign_each_;
     656             : };
     657             : 
     658             : 
     659             : class ExpressionStatement final : public Statement {
     660             :  public:
     661     1027849 :   void set_expression(Expression* e) { expression_ = e; }
     662     4029500 :   Expression* expression() const { return expression_; }
     663    47373179 :   bool IsJump() const { return expression_->IsThrow(); }
     664             : 
     665             :  private:
     666             :   friend class AstNodeFactory;
     667             : 
     668             :   ExpressionStatement(Expression* expression, int pos)
     669    22265993 :       : Statement(pos, kExpressionStatement), expression_(expression) {}
     670             : 
     671             :   Expression* expression_;
     672             : };
     673             : 
     674             : 
     675             : class JumpStatement : public Statement {
     676             :  public:
     677             :   bool IsJump() const { return true; }
     678             : 
     679             :  protected:
     680             :   JumpStatement(int pos, NodeType type) : Statement(pos, type) {}
     681             : };
     682             : 
     683             : 
     684             : class ContinueStatement final : public JumpStatement {
     685             :  public:
     686             :   IterationStatement* target() const { return target_; }
     687             : 
     688             :  private:
     689             :   friend class AstNodeFactory;
     690             : 
     691             :   ContinueStatement(IterationStatement* target, int pos)
     692       36958 :       : JumpStatement(pos, kContinueStatement), target_(target) {}
     693             : 
     694             :   IterationStatement* target_;
     695             : };
     696             : 
     697             : 
     698             : class BreakStatement final : public JumpStatement {
     699             :  public:
     700             :   BreakableStatement* target() const { return target_; }
     701             : 
     702             :  private:
     703             :   friend class AstNodeFactory;
     704             : 
     705             :   BreakStatement(BreakableStatement* target, int pos)
     706       96368 :       : JumpStatement(pos, kBreakStatement), target_(target) {}
     707             : 
     708             :   BreakableStatement* target_;
     709             : };
     710             : 
     711             : 
     712             : class ReturnStatement final : public JumpStatement {
     713             :  public:
     714             :   enum Type { kNormal, kAsyncReturn };
     715             :   Expression* expression() const { return expression_; }
     716             : 
     717           0 :   void set_expression(Expression* e) { expression_ = e; }
     718             :   Type type() const { return TypeField::decode(bit_field_); }
     719     2172321 :   bool is_async_return() const { return type() == kAsyncReturn; }
     720             : 
     721             :   int end_position() const { return end_position_; }
     722             : 
     723             :  private:
     724             :   friend class AstNodeFactory;
     725             : 
     726             :   ReturnStatement(Expression* expression, Type type, int pos, int end_position)
     727             :       : JumpStatement(pos, kReturnStatement),
     728             :         expression_(expression),
     729     4106030 :         end_position_(end_position) {
     730       16887 :     bit_field_ |= TypeField::encode(type);
     731             :   }
     732             : 
     733             :   Expression* expression_;
     734             :   int end_position_;
     735             : 
     736             :   class TypeField
     737             :       : public BitField<Type, JumpStatement::kNextBitFieldIndex, 1> {};
     738             : };
     739             : 
     740             : 
     741             : class WithStatement final : public Statement {
     742             :  public:
     743             :   Scope* scope() { return scope_; }
     744             :   Expression* expression() const { return expression_; }
     745           0 :   void set_expression(Expression* e) { expression_ = e; }
     746             :   Statement* statement() const { return statement_; }
     747        3165 :   void set_statement(Statement* s) { statement_ = s; }
     748             : 
     749             :  private:
     750             :   friend class AstNodeFactory;
     751             : 
     752             :   WithStatement(Scope* scope, Expression* expression, Statement* statement,
     753             :                 int pos)
     754             :       : Statement(pos, kWithStatement),
     755             :         scope_(scope),
     756             :         expression_(expression),
     757       36838 :         statement_(statement) {}
     758             : 
     759             :   Scope* scope_;
     760             :   Expression* expression_;
     761             :   Statement* statement_;
     762             : };
     763             : 
     764             : class CaseClause final : public ZoneObject {
     765             :  public:
     766             :   bool is_default() const { return label_ == nullptr; }
     767             :   Expression* label() const {
     768             :     DCHECK(!is_default());
     769             :     return label_;
     770             :   }
     771           0 :   void set_label(Expression* e) { label_ = e; }
     772             :   ZoneList<Statement*>* statements() const { return statements_; }
     773             : 
     774             :  private:
     775             :   friend class AstNodeFactory;
     776             : 
     777             :   CaseClause(Expression* label, ZoneList<Statement*>* statements);
     778             : 
     779             :   Expression* label_;
     780             :   ZoneList<Statement*>* statements_;
     781             : };
     782             : 
     783             : 
     784             : class SwitchStatement final : public BreakableStatement {
     785             :  public:
     786             :   ZoneList<const AstRawString*>* labels() const { return labels_; }
     787             : 
     788             :   Expression* tag() const { return tag_; }
     789         920 :   void set_tag(Expression* t) { tag_ = t; }
     790             : 
     791             :   ZoneList<CaseClause*>* cases() { return &cases_; }
     792             : 
     793             :  private:
     794             :   friend class AstNodeFactory;
     795             : 
     796             :   SwitchStatement(Zone* zone, ZoneList<const AstRawString*>* labels,
     797             :                   Expression* tag, int pos)
     798             :       : BreakableStatement(TARGET_FOR_ANONYMOUS, pos, kSwitchStatement),
     799             :         labels_(labels),
     800             :         tag_(tag),
     801       20224 :         cases_(4, zone) {}
     802             : 
     803             :   ZoneList<const AstRawString*>* labels_;
     804             :   Expression* tag_;
     805             :   ZoneList<CaseClause*> cases_;
     806             : };
     807             : 
     808             : 
     809             : // If-statements always have non-null references to their then- and
     810             : // else-parts. When parsing if-statements with no explicit else-part,
     811             : // the parser implicitly creates an empty statement. Use the
     812             : // HasThenStatement() and HasElseStatement() functions to check if a
     813             : // given if-statement has a then- or an else-part containing code.
     814             : class IfStatement final : public Statement {
     815             :  public:
     816     2012151 :   bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
     817     2898552 :   bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
     818             : 
     819             :   Expression* condition() const { return condition_; }
     820             :   Statement* then_statement() const { return then_statement_; }
     821             :   Statement* else_statement() const { return else_statement_; }
     822             : 
     823           0 :   void set_condition(Expression* e) { condition_ = e; }
     824        2617 :   void set_then_statement(Statement* s) { then_statement_ = s; }
     825        2617 :   void set_else_statement(Statement* s) { else_statement_ = s; }
     826             : 
     827     3797420 :   bool IsJump() const {
     828     1756365 :     return HasThenStatement() && then_statement()->IsJump()
     829     2955792 :         && HasElseStatement() && else_statement()->IsJump();
     830             :   }
     831             : 
     832             :  private:
     833             :   friend class AstNodeFactory;
     834             : 
     835             :   IfStatement(Expression* condition, Statement* then_statement,
     836             :               Statement* else_statement, int pos)
     837             :       : Statement(pos, kIfStatement),
     838             :         condition_(condition),
     839             :         then_statement_(then_statement),
     840     3119602 :         else_statement_(else_statement) {}
     841             : 
     842             :   Expression* condition_;
     843             :   Statement* then_statement_;
     844             :   Statement* else_statement_;
     845             : };
     846             : 
     847             : 
     848             : class TryStatement : public Statement {
     849             :  public:
     850             :   Block* try_block() const { return try_block_; }
     851        9531 :   void set_try_block(Block* b) { try_block_ = b; }
     852             : 
     853             :  protected:
     854             :   TryStatement(Block* try_block, int pos, NodeType type)
     855      669616 :       : Statement(pos, type), try_block_(try_block) {}
     856             : 
     857             :  private:
     858             :   Block* try_block_;
     859             : };
     860             : 
     861             : 
     862             : class TryCatchStatement final : public TryStatement {
     863             :  public:
     864             :   Scope* scope() { return scope_; }
     865             :   Block* catch_block() const { return catch_block_; }
     866        6371 :   void set_catch_block(Block* b) { catch_block_ = b; }
     867             : 
     868             :   // Prediction of whether exceptions thrown into the handler for this try block
     869             :   // will be caught.
     870             :   //
     871             :   // BytecodeGenerator tracks the state of catch prediction, which can change
     872             :   // with each TryCatchStatement encountered. The tracked catch prediction is
     873             :   // later compiled into the code's handler table. The runtime uses this
     874             :   // information to implement a feature that notifies the debugger when an
     875             :   // uncaught exception is thrown, _before_ the exception propagates to the top.
     876             :   //
     877             :   // If this try/catch statement is meant to rethrow (HandlerTable::UNCAUGHT),
     878             :   // the catch prediction value is set to the same value as the surrounding
     879             :   // catch prediction.
     880             :   //
     881             :   // Since it's generally undecidable whether an exception will be caught, our
     882             :   // prediction is only an approximation.
     883             :   // ---------------------------------------------------------------------------
     884             :   inline HandlerTable::CatchPrediction GetCatchPrediction(
     885             :       HandlerTable::CatchPrediction outer_catch_prediction) const {
     886      102122 :     if (catch_prediction_ == HandlerTable::UNCAUGHT) {
     887             :       return outer_catch_prediction;
     888             :     }
     889             :     return catch_prediction_;
     890             :   }
     891             : 
     892             :   // Indicates whether or not code should be generated to clear the pending
     893             :   // exception. The pending exception is cleared for cases where the exception
     894             :   // is not guaranteed to be rethrown, indicated by the value
     895             :   // HandlerTable::UNCAUGHT. If both the current and surrounding catch handler's
     896             :   // are predicted uncaught, the exception is not cleared.
     897             :   //
     898             :   // If this handler is not going to simply rethrow the exception, this method
     899             :   // indicates that the isolate's pending exception message should be cleared
     900             :   // before executing the catch_block.
     901             :   // In the normal use case, this flag is always on because the message object
     902             :   // is not needed anymore when entering the catch block and should not be
     903             :   // kept alive.
     904             :   // The use case where the flag is off is when the catch block is guaranteed
     905             :   // to rethrow the caught exception (using %ReThrow), which reuses the
     906             :   // pending message instead of generating a new one.
     907             :   // (When the catch block doesn't rethrow but is guaranteed to perform an
     908             :   // ordinary throw, not clearing the old message is safe but not very
     909             :   // useful.)
     910             :   inline bool ShouldClearPendingException(
     911             :       HandlerTable::CatchPrediction outer_catch_prediction) const {
     912      102122 :     return catch_prediction_ != HandlerTable::UNCAUGHT ||
     913             :            outer_catch_prediction != HandlerTable::UNCAUGHT;
     914             :   }
     915             : 
     916             :  private:
     917             :   friend class AstNodeFactory;
     918             : 
     919             :   TryCatchStatement(Block* try_block, Scope* scope, Block* catch_block,
     920             :                     HandlerTable::CatchPrediction catch_prediction, int pos)
     921             :       : TryStatement(try_block, pos, kTryCatchStatement),
     922             :         scope_(scope),
     923             :         catch_block_(catch_block),
     924      454749 :         catch_prediction_(catch_prediction) {}
     925             : 
     926             :   Scope* scope_;
     927             :   Block* catch_block_;
     928             :   HandlerTable::CatchPrediction catch_prediction_;
     929             : };
     930             : 
     931             : 
     932             : class TryFinallyStatement final : public TryStatement {
     933             :  public:
     934             :   Block* finally_block() const { return finally_block_; }
     935         227 :   void set_finally_block(Block* b) { finally_block_ = b; }
     936             : 
     937             :  private:
     938             :   friend class AstNodeFactory;
     939             : 
     940             :   TryFinallyStatement(Block* try_block, Block* finally_block, int pos)
     941             :       : TryStatement(try_block, pos, kTryFinallyStatement),
     942      214867 :         finally_block_(finally_block) {}
     943             : 
     944             :   Block* finally_block_;
     945             : };
     946             : 
     947             : 
     948             : class DebuggerStatement final : public Statement {
     949             :  private:
     950             :   friend class AstNodeFactory;
     951             : 
     952             :   explicit DebuggerStatement(int pos) : Statement(pos, kDebuggerStatement) {}
     953             : };
     954             : 
     955             : 
     956             : class EmptyStatement final : public Statement {
     957             :  private:
     958             :   friend class AstNodeFactory;
     959             :   explicit EmptyStatement(int pos) : Statement(pos, kEmptyStatement) {}
     960             : };
     961             : 
     962             : 
     963             : // Delegates to another statement, which may be overwritten.
     964             : // This was introduced to implement ES2015 Annex B3.3 for conditionally making
     965             : // sloppy-mode block-scoped functions have a var binding, which is changed
     966             : // from one statement to another during parsing.
     967             : class SloppyBlockFunctionStatement final : public Statement {
     968             :  public:
     969             :   Statement* statement() const { return statement_; }
     970        8433 :   void set_statement(Statement* statement) { statement_ = statement; }
     971             : 
     972             :  private:
     973             :   friend class AstNodeFactory;
     974             : 
     975             :   explicit SloppyBlockFunctionStatement(Statement* statement)
     976             :       : Statement(kNoSourcePosition, kSloppyBlockFunctionStatement),
     977        8566 :         statement_(statement) {}
     978             : 
     979             :   Statement* statement_;
     980             : };
     981             : 
     982             : 
     983             : class Literal final : public Expression {
     984             :  public:
     985             :   // Returns true if literal represents a property name (i.e. cannot be parsed
     986             :   // as array indices).
     987     8972171 :   bool IsPropertyName() const { return value_->IsPropertyName(); }
     988             : 
     989     5480034 :   const AstRawString* AsRawPropertyName() {
     990             :     DCHECK(IsPropertyName());
     991    10960068 :     return value_->AsString();
     992             :   }
     993             : 
     994      207295 :   Smi* AsSmiLiteral() {
     995             :     DCHECK(IsSmiLiteral());
     996      207295 :     return raw_value()->AsSmi();
     997             :   }
     998             : 
     999       25218 :   bool ToBooleanIsTrue() const { return raw_value()->BooleanValue(); }
    1000       34710 :   bool ToBooleanIsFalse() const { return !raw_value()->BooleanValue(); }
    1001             : 
    1002             :   Handle<Object> value() const { return value_->value(); }
    1003     6768880 :   const AstValue* raw_value() const { return value_; }
    1004             : 
    1005             :   // Support for using Literal as a HashMap key. NOTE: Currently, this works
    1006             :   // only for string and number literals!
    1007             :   uint32_t Hash();
    1008             :   static bool Match(void* literal1, void* literal2);
    1009             : 
    1010             :  private:
    1011             :   friend class AstNodeFactory;
    1012             : 
    1013             :   Literal(const AstValue* value, int position)
    1014    47506584 :       : Expression(position, kLiteral), value_(value) {}
    1015             : 
    1016             :   const AstValue* value_;
    1017             : };
    1018             : 
    1019             : // Base class for literals that need space in the type feedback vector.
    1020             : class MaterializedLiteral : public Expression {
    1021             :  public:
    1022             :   // A Materializedliteral is simple if the values consist of only
    1023             :   // constants and simple object and array literals.
    1024             :   bool IsSimple() const;
    1025             : 
    1026             :  protected:
    1027             :   MaterializedLiteral(int pos, NodeType type) : Expression(pos, type) {}
    1028             : 
    1029             :   friend class CompileTimeValue;
    1030             :   friend class ArrayLiteral;
    1031             :   friend class ObjectLiteral;
    1032             : 
    1033             :   // Populate the depth field and any flags the literal has, returns the depth.
    1034             :   int InitDepthAndFlags();
    1035             : 
    1036             :   bool NeedsInitialAllocationSite();
    1037             : 
    1038             :   // Populate the constant properties/elements fixed array.
    1039             :   void BuildConstants(Isolate* isolate);
    1040             : 
    1041             :   // If the expression is a literal, return the literal value;
    1042             :   // if the expression is a materialized literal and is simple return a
    1043             :   // compile time value as encoded by CompileTimeValue::GetValue().
    1044             :   // Otherwise, return undefined literal as the placeholder
    1045             :   // in the object literal boilerplate.
    1046             :   Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate);
    1047             : };
    1048             : 
    1049             : // Node for capturing a regexp literal.
    1050             : class RegExpLiteral final : public MaterializedLiteral {
    1051             :  public:
    1052         275 :   Handle<String> pattern() const { return pattern_->string(); }
    1053             :   const AstRawString* raw_pattern() const { return pattern_; }
    1054             :   int flags() const { return flags_; }
    1055             : 
    1056             :  private:
    1057             :   friend class AstNodeFactory;
    1058             : 
    1059             :   RegExpLiteral(const AstRawString* pattern, int flags, int pos)
    1060             :       : MaterializedLiteral(pos, kRegExpLiteral),
    1061             :         flags_(flags),
    1062       62028 :         pattern_(pattern) {}
    1063             : 
    1064             :   int const flags_;
    1065             :   const AstRawString* const pattern_;
    1066             : };
    1067             : 
    1068             : // Base class for Array and Object literals, providing common code for handling
    1069             : // nested subliterals.
    1070             : class AggregateLiteral : public MaterializedLiteral {
    1071             :  public:
    1072             :   enum Flags {
    1073             :     kNoFlags = 0,
    1074             :     kIsShallow = 1,
    1075             :     kDisableMementos = 1 << 1,
    1076             :     kNeedsInitialAllocationSite = 1 << 2,
    1077             :   };
    1078             : 
    1079      673822 :   bool is_initialized() const { return 0 < depth_; }
    1080             :   int depth() const {
    1081             :     DCHECK(is_initialized());
    1082      884487 :     return depth_;
    1083             :   }
    1084             : 
    1085             :   bool is_shallow() const { return depth() == 1; }
    1086             :   bool needs_initial_allocation_site() const {
    1087             :     return NeedsInitialAllocationSiteField::decode(bit_field_);
    1088             :   }
    1089             : 
    1090      375020 :   int ComputeFlags(bool disable_mementos = false) const {
    1091             :     int flags = kNoFlags;
    1092      375020 :     if (is_shallow()) flags |= kIsShallow;
    1093      263561 :     if (disable_mementos) flags |= kDisableMementos;
    1094      375020 :     if (needs_initial_allocation_site()) flags |= kNeedsInitialAllocationSite;
    1095             :     return flags;
    1096             :   }
    1097             : 
    1098             :   // An AggregateLiteral is simple if the values consist of only
    1099             :   // constants and simple object and array literals.
    1100             :   bool is_simple() const { return IsSimpleField::decode(bit_field_); }
    1101             : 
    1102             :  private:
    1103             :   int depth_ : 31;
    1104             :   class NeedsInitialAllocationSiteField
    1105             :       : public BitField<bool, MaterializedLiteral::kNextBitFieldIndex, 1> {};
    1106             :   class IsSimpleField
    1107             :       : public BitField<bool, NeedsInitialAllocationSiteField::kNext, 1> {};
    1108             : 
    1109             :  protected:
    1110             :   friend class AstNodeFactory;
    1111             :   AggregateLiteral(int pos, NodeType type)
    1112     1414395 :       : MaterializedLiteral(pos, type), depth_(0) {
    1113             :     bit_field_ |= NeedsInitialAllocationSiteField::encode(false) |
    1114             :                   IsSimpleField::encode(false);
    1115             :   }
    1116             : 
    1117             :   void set_is_simple(bool is_simple) {
    1118     1203694 :     bit_field_ = IsSimpleField::update(bit_field_, is_simple);
    1119             :   }
    1120             : 
    1121             :   void set_depth(int depth) {
    1122             :     DCHECK(!is_initialized());
    1123      601847 :     depth_ = depth;
    1124             :   }
    1125             : 
    1126             :   void set_needs_initial_allocation_site(bool required) {
    1127      601847 :     bit_field_ = NeedsInitialAllocationSiteField::update(bit_field_, required);
    1128             :   }
    1129             : 
    1130             :   static const uint8_t kNextBitFieldIndex = IsSimpleField::kNext;
    1131             : };
    1132             : 
    1133             : // Common supertype for ObjectLiteralProperty and ClassLiteralProperty
    1134             : class LiteralProperty : public ZoneObject {
    1135             :  public:
    1136             :   Expression* key() const { return key_; }
    1137       41393 :   Expression* value() const { return value_; }
    1138           0 :   void set_key(Expression* e) { key_ = e; }
    1139           0 :   void set_value(Expression* e) { value_ = e; }
    1140             : 
    1141             :   bool is_computed_name() const { return is_computed_name_; }
    1142             :   bool NeedsSetFunctionName() const;
    1143             : 
    1144             :  protected:
    1145             :   LiteralProperty(Expression* key, Expression* value, bool is_computed_name)
    1146     4230338 :       : key_(key), value_(value), is_computed_name_(is_computed_name) {}
    1147             : 
    1148             :   Expression* key_;
    1149             :   Expression* value_;
    1150             :   bool is_computed_name_;
    1151             : };
    1152             : 
    1153             : // Property is used for passing information
    1154             : // about an object literal's properties from the parser
    1155             : // to the code generator.
    1156             : class ObjectLiteralProperty final : public LiteralProperty {
    1157             :  public:
    1158             :   enum Kind : uint8_t {
    1159             :     CONSTANT,              // Property with constant value (compile time).
    1160             :     COMPUTED,              // Property with computed value (execution time).
    1161             :     MATERIALIZED_LITERAL,  // Property value is a materialized literal.
    1162             :     GETTER,
    1163             :     SETTER,     // Property is an accessor function.
    1164             :     PROTOTYPE,  // Property is __proto__.
    1165             :     SPREAD
    1166             :   };
    1167             : 
    1168             :   Kind kind() const { return kind_; }
    1169             : 
    1170             :   bool IsCompileTimeValue() const;
    1171             : 
    1172             :   void set_emit_store(bool emit_store);
    1173             :   bool emit_store() const;
    1174             : 
    1175             :   bool IsNullPrototype() const {
    1176       55211 :     return IsPrototype() && value()->IsNullLiteral();
    1177             :   }
    1178    17796916 :   bool IsPrototype() const { return kind() == PROTOTYPE; }
    1179             : 
    1180             :  private:
    1181             :   friend class AstNodeFactory;
    1182             : 
    1183             :   ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
    1184             :                         bool is_computed_name);
    1185             :   ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
    1186             :                         Expression* value, bool is_computed_name);
    1187             : 
    1188             :   Kind kind_;
    1189             :   bool emit_store_;
    1190             : };
    1191             : 
    1192             : 
    1193             : // An object literal has a boilerplate object that is used
    1194             : // for minimizing the work when constructing it at runtime.
    1195             : class ObjectLiteral final : public AggregateLiteral {
    1196             :  public:
    1197             :   typedef ObjectLiteralProperty Property;
    1198             : 
    1199             :   Handle<BoilerplateDescription> constant_properties() const {
    1200             :     DCHECK(!constant_properties_.is_null());
    1201             :     return constant_properties_;
    1202             :   }
    1203      501318 :   int properties_count() const { return boilerplate_properties_; }
    1204             :   ZoneList<Property*>* properties() const { return properties_; }
    1205             :   bool has_elements() const { return HasElementsField::decode(bit_field_); }
    1206             :   bool has_rest_property() const {
    1207             :     return HasRestPropertyField::decode(bit_field_);
    1208             :   }
    1209             :   bool fast_elements() const { return FastElementsField::decode(bit_field_); }
    1210             :   bool has_null_prototype() const {
    1211             :     return HasNullPrototypeField::decode(bit_field_);
    1212             :   }
    1213             : 
    1214      652359 :   bool is_empty() const {
    1215             :     DCHECK(is_initialized());
    1216      652359 :     return !has_elements() && properties_count() == 0 &&
    1217       47087 :            properties()->length() == 0;
    1218             :   }
    1219             : 
    1220      303785 :   bool IsEmptyObjectLiteral() const {
    1221      344009 :     return is_empty() && !has_null_prototype();
    1222             :   }
    1223             : 
    1224             :   // Populate the depth field and flags, returns the depth.
    1225             :   int InitDepthAndFlags();
    1226             : 
    1227             :   // Get the constant properties fixed array, populating it if necessary.
    1228             :   Handle<BoilerplateDescription> GetOrBuildConstantProperties(
    1229             :       Isolate* isolate) {
    1230      256698 :     if (constant_properties_.is_null()) {
    1231      234254 :       BuildConstantProperties(isolate);
    1232             :     }
    1233             :     return constant_properties();
    1234             :   }
    1235             : 
    1236             :   // Populate the constant properties fixed array.
    1237             :   void BuildConstantProperties(Isolate* isolate);
    1238             : 
    1239             :   // Mark all computed expressions that are bound to a key that
    1240             :   // is shadowed by a later occurrence of the same key. For the
    1241             :   // marked expressions, no store code is emitted.
    1242             :   void CalculateEmitStore(Zone* zone);
    1243             : 
    1244             :   // Determines whether the {CreateShallowObjectLiteratal} builtin can be used.
    1245             :   bool IsFastCloningSupported() const;
    1246             : 
    1247             :   // Assemble bitfield of flags for the CreateObjectLiteral helper.
    1248      263561 :   int ComputeFlags(bool disable_mementos = false) const {
    1249             :     int flags = AggregateLiteral::ComputeFlags(disable_mementos);
    1250      263561 :     if (fast_elements()) flags |= kFastElements;
    1251      263561 :     if (has_null_prototype()) flags |= kHasNullPrototype;
    1252      263561 :     return flags;
    1253             :   }
    1254             : 
    1255       25439 :   int EncodeLiteralType() {
    1256             :     int flags = kNoFlags;
    1257       25439 :     if (fast_elements()) flags |= kFastElements;
    1258       25439 :     if (has_null_prototype()) flags |= kHasNullPrototype;
    1259             :     return flags;
    1260             :   }
    1261             : 
    1262             :   enum Flags {
    1263             :     kFastElements = 1 << 3,
    1264             :     kHasNullPrototype = 1 << 4,
    1265             :   };
    1266             :   STATIC_ASSERT(
    1267             :       static_cast<int>(AggregateLiteral::kNeedsInitialAllocationSite) <
    1268             :       static_cast<int>(kFastElements));
    1269             : 
    1270             :   struct Accessors: public ZoneObject {
    1271        4000 :     Accessors() : getter(nullptr), setter(nullptr) {}
    1272             :     ObjectLiteralProperty* getter;
    1273             :     ObjectLiteralProperty* setter;
    1274             :   };
    1275             : 
    1276             :  private:
    1277             :   friend class AstNodeFactory;
    1278             : 
    1279             :   ObjectLiteral(ZoneList<Property*>* properties,
    1280             :                 uint32_t boilerplate_properties, int pos,
    1281             :                 bool has_rest_property)
    1282             :       : AggregateLiteral(pos, kObjectLiteral),
    1283             :         boilerplate_properties_(boilerplate_properties),
    1284     1522458 :         properties_(properties) {
    1285             :     bit_field_ |= HasElementsField::encode(false) |
    1286             :                   HasRestPropertyField::encode(has_rest_property) |
    1287             :                   FastElementsField::encode(false) |
    1288      761229 :                   HasNullPrototypeField::encode(false);
    1289             :   }
    1290             : 
    1291             :   void InitFlagsForPendingNullPrototype(int i);
    1292             : 
    1293             :   void set_has_elements(bool has_elements) {
    1294      334337 :     bit_field_ = HasElementsField::update(bit_field_, has_elements);
    1295             :   }
    1296             :   void set_fast_elements(bool fast_elements) {
    1297      334337 :     bit_field_ = FastElementsField::update(bit_field_, fast_elements);
    1298             :   }
    1299             :   void set_has_null_protoype(bool has_null_prototype) {
    1300       54978 :     bit_field_ = HasNullPrototypeField::update(bit_field_, has_null_prototype);
    1301             :   }
    1302             : 
    1303             :   uint32_t boilerplate_properties_;
    1304             :   Handle<BoilerplateDescription> constant_properties_;
    1305             :   ZoneList<Property*>* properties_;
    1306             : 
    1307             :   class HasElementsField
    1308             :       : public BitField<bool, AggregateLiteral::kNextBitFieldIndex, 1> {};
    1309             :   class HasRestPropertyField
    1310             :       : public BitField<bool, HasElementsField::kNext, 1> {};
    1311             :   class FastElementsField
    1312             :       : public BitField<bool, HasRestPropertyField::kNext, 1> {};
    1313             :   class HasNullPrototypeField
    1314             :       : public BitField<bool, FastElementsField::kNext, 1> {};
    1315             : };
    1316             : 
    1317             : 
    1318             : // A map from property names to getter/setter pairs allocated in the zone.
    1319             : class AccessorTable
    1320             :     : public base::TemplateHashMap<Literal, ObjectLiteral::Accessors,
    1321             :                                    bool (*)(void*, void*),
    1322             :                                    ZoneAllocationPolicy> {
    1323             :  public:
    1324             :   explicit AccessorTable(Zone* zone)
    1325             :       : base::TemplateHashMap<Literal, ObjectLiteral::Accessors,
    1326             :                               bool (*)(void*, void*), ZoneAllocationPolicy>(
    1327             :             Literal::Match, ZoneAllocationPolicy(zone)),
    1328      263561 :         zone_(zone) {}
    1329             : 
    1330        4592 :   Iterator lookup(Literal* literal) {
    1331        9184 :     Iterator it = find(literal, true, ZoneAllocationPolicy(zone_));
    1332        4592 :     if (it->second == nullptr) {
    1333        8000 :       it->second = new (zone_) ObjectLiteral::Accessors();
    1334             :     }
    1335        4592 :     return it;
    1336             :   }
    1337             : 
    1338             :  private:
    1339             :   Zone* zone_;
    1340             : };
    1341             : 
    1342             : 
    1343             : // An array literal has a literals object that is used
    1344             : // for minimizing the work when constructing it at runtime.
    1345             : class ArrayLiteral final : public AggregateLiteral {
    1346             :  public:
    1347             :   Handle<ConstantElementsPair> constant_elements() const {
    1348             :     return constant_elements_;
    1349             :   }
    1350             : 
    1351             :   ZoneList<Expression*>* values() const { return values_; }
    1352             : 
    1353             :   bool is_empty() const;
    1354             : 
    1355             :   // Populate the depth field and flags, returns the depth.
    1356             :   int InitDepthAndFlags();
    1357             : 
    1358             :   // Get the constant elements fixed array, populating it if necessary.
    1359             :   Handle<ConstantElementsPair> GetOrBuildConstantElements(Isolate* isolate) {
    1360      111459 :     if (constant_elements_.is_null()) {
    1361      107432 :       BuildConstantElements(isolate);
    1362             :     }
    1363             :     return constant_elements();
    1364             :   }
    1365             : 
    1366             :   // Populate the constant elements fixed array.
    1367             :   void BuildConstantElements(Isolate* isolate);
    1368             : 
    1369             :   // Determines whether the {CreateShallowArrayLiteral} builtin can be used.
    1370             :   bool IsFastCloningSupported() const;
    1371             : 
    1372             :   // Assemble bitfield of flags for the CreateArrayLiteral helper.
    1373             :   int ComputeFlags(bool disable_mementos = false) const {
    1374             :     return AggregateLiteral::ComputeFlags(disable_mementos);
    1375             :   }
    1376             : 
    1377             :   // Provide a mechanism for iterating through values to rewrite spreads.
    1378        2112 :   ZoneList<Expression*>::iterator FirstSpread() const {
    1379        4224 :     return (first_spread_index_ >= 0) ? values_->begin() + first_spread_index_
    1380        6336 :                                       : values_->end();
    1381             :   }
    1382       15764 :   ZoneList<Expression*>::iterator EndValue() const { return values_->end(); }
    1383             : 
    1384             :   // Rewind an array literal omitting everything from the first spread on.
    1385             :   void RewindSpreads();
    1386             : 
    1387             :  private:
    1388             :   friend class AstNodeFactory;
    1389             : 
    1390             :   ArrayLiteral(ZoneList<Expression*>* values, int first_spread_index, int pos)
    1391             :       : AggregateLiteral(pos, kArrayLiteral),
    1392             :         first_spread_index_(first_spread_index),
    1393     1306332 :         values_(values) {}
    1394             : 
    1395             :   int first_spread_index_;
    1396             :   Handle<ConstantElementsPair> constant_elements_;
    1397             :   ZoneList<Expression*>* values_;
    1398             : };
    1399             : 
    1400             : 
    1401             : class VariableProxy final : public Expression {
    1402             :  public:
    1403     2607059 :   bool IsValidReferenceExpression() const {
    1404     5213623 :     return !is_this() && !is_new_target();
    1405             :   }
    1406             : 
    1407     1875787 :   Handle<String> name() const { return raw_name()->string(); }
    1408   158845067 :   const AstRawString* raw_name() const {
    1409   158845067 :     return is_resolved() ? var_->raw_name() : raw_name_;
    1410             :   }
    1411             : 
    1412       73998 :   Variable* var() const {
    1413             :     DCHECK(is_resolved());
    1414       73998 :     return var_;
    1415             :   }
    1416             :   void set_var(Variable* v) {
    1417             :     DCHECK(!is_resolved());
    1418             :     DCHECK_NOT_NULL(v);
    1419    57586102 :     var_ = v;
    1420             :   }
    1421             : 
    1422    92173110 :   bool is_this() const { return IsThisField::decode(bit_field_); }
    1423             : 
    1424             :   bool is_assigned() const { return IsAssignedField::decode(bit_field_); }
    1425     8302807 :   void set_is_assigned() {
    1426    24814406 :     bit_field_ = IsAssignedField::update(bit_field_, true);
    1427    12407203 :     if (is_resolved()) {
    1428             :       var()->set_maybe_assigned();
    1429             :     }
    1430     4846192 :   }
    1431             : 
    1432             :   bool is_resolved() const { return IsResolvedField::decode(bit_field_); }
    1433             :   void set_is_resolved() {
    1434   106153890 :     bit_field_ = IsResolvedField::update(bit_field_, true);
    1435             :   }
    1436             : 
    1437    85698406 :   bool is_new_target() const { return IsNewTargetField::decode(bit_field_); }
    1438             :   void set_is_new_target() {
    1439       26808 :     bit_field_ = IsNewTargetField::update(bit_field_, true);
    1440             :   }
    1441             : 
    1442             :   HoleCheckMode hole_check_mode() const {
    1443             :     HoleCheckMode mode = HoleCheckModeField::decode(bit_field_);
    1444             :     DCHECK_IMPLIES(mode == HoleCheckMode::kRequired,
    1445             :                    var()->binding_needs_init() ||
    1446             :                        var()->local_if_not_shadowed()->binding_needs_init());
    1447             :     return mode;
    1448             :   }
    1449             :   void set_needs_hole_check() {
    1450             :     bit_field_ =
    1451      789990 :         HoleCheckModeField::update(bit_field_, HoleCheckMode::kRequired);
    1452             :   }
    1453             : 
    1454             :   // Bind this proxy to the variable var.
    1455             :   void BindTo(Variable* var);
    1456             : 
    1457   115246808 :   void set_next_unresolved(VariableProxy* next) { next_unresolved_ = next; }
    1458             :   VariableProxy* next_unresolved() { return next_unresolved_; }
    1459             : 
    1460             :  private:
    1461             :   friend class AstNodeFactory;
    1462             : 
    1463             :   VariableProxy(Variable* var, int start_position);
    1464             : 
    1465             :   VariableProxy(const AstRawString* name, VariableKind variable_kind,
    1466             :                 int start_position)
    1467             :       : Expression(start_position, kVariableProxy),
    1468             :         raw_name_(name),
    1469   104008490 :         next_unresolved_(nullptr) {
    1470   104008490 :     bit_field_ |= IsThisField::encode(variable_kind == THIS_VARIABLE) |
    1471             :                   IsAssignedField::encode(false) |
    1472             :                   IsResolvedField::encode(false) |
    1473   104008490 :                   HoleCheckModeField::encode(HoleCheckMode::kElided);
    1474             :   }
    1475             : 
    1476             :   explicit VariableProxy(const VariableProxy* copy_from);
    1477             : 
    1478             :   class IsThisField : public BitField<bool, Expression::kNextBitFieldIndex, 1> {
    1479             :   };
    1480             :   class IsAssignedField : public BitField<bool, IsThisField::kNext, 1> {};
    1481             :   class IsResolvedField : public BitField<bool, IsAssignedField::kNext, 1> {};
    1482             :   class IsNewTargetField : public BitField<bool, IsResolvedField::kNext, 1> {};
    1483             :   class HoleCheckModeField
    1484             :       : public BitField<HoleCheckMode, IsNewTargetField::kNext, 1> {};
    1485             : 
    1486             :   union {
    1487             :     const AstRawString* raw_name_;  // if !is_resolved_
    1488             :     Variable* var_;                 // if is_resolved_
    1489             :   };
    1490             :   VariableProxy* next_unresolved_;
    1491             : };
    1492             : 
    1493             : 
    1494             : // Left-hand side can only be a property, a global or a (parameter or local)
    1495             : // slot.
    1496             : enum LhsKind {
    1497             :   VARIABLE,
    1498             :   NAMED_PROPERTY,
    1499             :   KEYED_PROPERTY,
    1500             :   NAMED_SUPER_PROPERTY,
    1501             :   KEYED_SUPER_PROPERTY
    1502             : };
    1503             : 
    1504             : 
    1505             : class Property final : public Expression {
    1506             :  public:
    1507             :   bool IsValidReferenceExpression() const { return true; }
    1508             : 
    1509     6693806 :   Expression* obj() const { return obj_; }
    1510          20 :   Expression* key() const { return key_; }
    1511             : 
    1512           0 :   void set_obj(Expression* e) { obj_ = e; }
    1513           0 :   void set_key(Expression* e) { key_ = e; }
    1514             : 
    1515    18096018 :   bool IsSuperAccess() { return obj()->IsSuperPropertyReference(); }
    1516             : 
    1517             :   // Returns the properties assign type.
    1518    21663522 :   static LhsKind GetAssignType(Property* property) {
    1519    13451462 :     if (property == nullptr) return VARIABLE;
    1520     8212060 :     bool super_access = property->IsSuperAccess();
    1521     8212060 :     return (property->key()->IsPropertyName())
    1522             :                ? (super_access ? NAMED_SUPER_PROPERTY : NAMED_PROPERTY)
    1523     8212059 :                : (super_access ? KEYED_SUPER_PROPERTY : KEYED_PROPERTY);
    1524             :   }
    1525             : 
    1526             :  private:
    1527             :   friend class AstNodeFactory;
    1528             : 
    1529             :   Property(Expression* obj, Expression* key, int pos)
    1530    14100012 :       : Expression(pos, kProperty), obj_(obj), key_(key) {
    1531             :   }
    1532             : 
    1533             :   Expression* obj_;
    1534             :   Expression* key_;
    1535             : };
    1536             : 
    1537             : 
    1538             : class Call final : public Expression {
    1539             :  public:
    1540             :   Expression* expression() const { return expression_; }
    1541             :   ZoneList<Expression*>* arguments() const { return arguments_; }
    1542             : 
    1543           0 :   void set_expression(Expression* e) { expression_ = e; }
    1544             : 
    1545             :   bool is_possibly_eval() const {
    1546             :     return IsPossiblyEvalField::decode(bit_field_);
    1547             :   }
    1548             : 
    1549             :   bool is_tagged_template() const {
    1550             :     return IsTaggedTemplateField::decode(bit_field_);
    1551             :   }
    1552             : 
    1553     2665847 :   bool only_last_arg_is_spread() {
    1554     7365487 :     return !arguments_->is_empty() && arguments_->last()->IsSpread();
    1555             :   }
    1556             : 
    1557             :   enum CallType {
    1558             :     GLOBAL_CALL,
    1559             :     WITH_CALL,
    1560             :     NAMED_PROPERTY_CALL,
    1561             :     KEYED_PROPERTY_CALL,
    1562             :     NAMED_SUPER_PROPERTY_CALL,
    1563             :     KEYED_SUPER_PROPERTY_CALL,
    1564             :     SUPER_CALL,
    1565             :     OTHER_CALL
    1566             :   };
    1567             : 
    1568             :   enum PossiblyEval {
    1569             :     IS_POSSIBLY_EVAL,
    1570             :     NOT_EVAL,
    1571             :   };
    1572             : 
    1573             :   // Helpers to determine how to handle the call.
    1574             :   CallType GetCallType() const;
    1575             : 
    1576             :   enum class TaggedTemplateTag { kTrue };
    1577             : 
    1578             :  private:
    1579             :   friend class AstNodeFactory;
    1580             : 
    1581             :   Call(Expression* expression, ZoneList<Expression*>* arguments, int pos,
    1582             :        PossiblyEval possibly_eval)
    1583             :       : Expression(pos, kCall),
    1584             :         expression_(expression),
    1585     5964393 :         arguments_(arguments) {
    1586             :     bit_field_ |=
    1587     5751773 :         IsPossiblyEvalField::encode(possibly_eval == IS_POSSIBLY_EVAL) |
    1588     5751773 :         IsTaggedTemplateField::encode(false);
    1589             :   }
    1590             : 
    1591             :   Call(Expression* expression, ZoneList<Expression*>* arguments, int pos,
    1592             :        TaggedTemplateTag tag)
    1593        6818 :       : Expression(pos, kCall), expression_(expression), arguments_(arguments) {
    1594             :     bit_field_ |= IsPossiblyEvalField::encode(false) |
    1595        6818 :                   IsTaggedTemplateField::encode(true);
    1596             :   }
    1597             : 
    1598             :   class IsPossiblyEvalField
    1599             :       : public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
    1600             :   class IsTaggedTemplateField
    1601             :       : public BitField<bool, IsPossiblyEvalField::kNext, 1> {};
    1602             : 
    1603             :   Expression* expression_;
    1604             :   ZoneList<Expression*>* arguments_;
    1605             : };
    1606             : 
    1607             : 
    1608             : class CallNew final : public Expression {
    1609             :  public:
    1610             :   Expression* expression() const { return expression_; }
    1611             :   ZoneList<Expression*>* arguments() const { return arguments_; }
    1612             : 
    1613           0 :   void set_expression(Expression* e) { expression_ = e; }
    1614             : 
    1615      156236 :   bool only_last_arg_is_spread() {
    1616      324140 :     return !arguments_->is_empty() && arguments_->last()->IsSpread();
    1617             :   }
    1618             : 
    1619             :  private:
    1620             :   friend class AstNodeFactory;
    1621             : 
    1622             :   CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos)
    1623             :       : Expression(pos, kCallNew),
    1624             :         expression_(expression),
    1625      460282 :         arguments_(arguments) {
    1626             :   }
    1627             : 
    1628             :   Expression* expression_;
    1629             :   ZoneList<Expression*>* arguments_;
    1630             : };
    1631             : 
    1632             : 
    1633             : // The CallRuntime class does not represent any official JavaScript
    1634             : // language construct. Instead it is used to call a C or JS function
    1635             : // with a set of arguments. This is used from the builtins that are
    1636             : // implemented in JavaScript (see "v8natives.js").
    1637             : class CallRuntime final : public Expression {
    1638             :  public:
    1639             :   ZoneList<Expression*>* arguments() const { return arguments_; }
    1640             :   bool is_jsruntime() const { return function_ == nullptr; }
    1641             : 
    1642             :   int context_index() const {
    1643             :     DCHECK(is_jsruntime());
    1644             :     return context_index_;
    1645             :   }
    1646             :   void set_context_index(int index) {
    1647             :     DCHECK(is_jsruntime());
    1648             :     context_index_ = index;
    1649             :   }
    1650             :   const Runtime::Function* function() const {
    1651             :     DCHECK(!is_jsruntime());
    1652             :     return function_;
    1653             :   }
    1654             : 
    1655             :   const char* debug_name();
    1656             : 
    1657             :  private:
    1658             :   friend class AstNodeFactory;
    1659             : 
    1660             :   CallRuntime(const Runtime::Function* function,
    1661             :               ZoneList<Expression*>* arguments, int pos)
    1662             :       : Expression(pos, kCallRuntime),
    1663             :         function_(function),
    1664     2514211 :         arguments_(arguments) {}
    1665             :   CallRuntime(int context_index, ZoneList<Expression*>* arguments, int pos)
    1666             :       : Expression(pos, kCallRuntime),
    1667             :         context_index_(context_index),
    1668             :         function_(nullptr),
    1669      263520 :         arguments_(arguments) {}
    1670             : 
    1671             :   int context_index_;
    1672             :   const Runtime::Function* function_;
    1673             :   ZoneList<Expression*>* arguments_;
    1674             : };
    1675             : 
    1676             : 
    1677             : class UnaryOperation final : public Expression {
    1678             :  public:
    1679             :   Token::Value op() const { return OperatorField::decode(bit_field_); }
    1680             :   Expression* expression() const { return expression_; }
    1681           0 :   void set_expression(Expression* e) { expression_ = e; }
    1682             : 
    1683             :  private:
    1684             :   friend class AstNodeFactory;
    1685             : 
    1686             :   UnaryOperation(Token::Value op, Expression* expression, int pos)
    1687     1817408 :       : Expression(pos, kUnaryOperation), expression_(expression) {
    1688     1817408 :     bit_field_ |= OperatorField::encode(op);
    1689             :     DCHECK(Token::IsUnaryOp(op));
    1690             :   }
    1691             : 
    1692             :   Expression* expression_;
    1693             : 
    1694             :   class OperatorField
    1695             :       : public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
    1696             : };
    1697             : 
    1698             : 
    1699             : class BinaryOperation final : public Expression {
    1700             :  public:
    1701             :   Token::Value op() const { return OperatorField::decode(bit_field_); }
    1702             :   Expression* left() const { return left_; }
    1703           0 :   void set_left(Expression* e) { left_ = e; }
    1704             :   Expression* right() const { return right_; }
    1705           0 :   void set_right(Expression* e) { right_ = e; }
    1706             : 
    1707             :   // Returns true if one side is a Smi literal, returning the other side's
    1708             :   // sub-expression in |subexpr| and the literal Smi in |literal|.
    1709             :   bool IsSmiLiteralOperation(Expression** subexpr, Smi** literal);
    1710             : 
    1711             :  private:
    1712             :   friend class AstNodeFactory;
    1713             : 
    1714             :   BinaryOperation(Token::Value op, Expression* left, Expression* right, int pos)
    1715     3170198 :       : Expression(pos, kBinaryOperation), left_(left), right_(right) {
    1716     3170198 :     bit_field_ |= OperatorField::encode(op);
    1717             :     DCHECK(Token::IsBinaryOp(op));
    1718             :   }
    1719             : 
    1720             :   Expression* left_;
    1721             :   Expression* right_;
    1722             : 
    1723             :   class OperatorField
    1724             :       : public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
    1725             : };
    1726             : 
    1727             : 
    1728             : class CountOperation final : public Expression {
    1729             :  public:
    1730             :   bool is_prefix() const { return IsPrefixField::decode(bit_field_); }
    1731      204632 :   bool is_postfix() const { return !is_prefix(); }
    1732             : 
    1733             :   Token::Value op() const { return TokenField::decode(bit_field_); }
    1734             : 
    1735             :   Expression* expression() const { return expression_; }
    1736           0 :   void set_expression(Expression* e) { expression_ = e; }
    1737             : 
    1738             :  private:
    1739             :   friend class AstNodeFactory;
    1740             : 
    1741             :   CountOperation(Token::Value op, bool is_prefix, Expression* expr, int pos)
    1742      629751 :       : Expression(pos, kCountOperation), expression_(expr) {
    1743      629751 :     bit_field_ |= IsPrefixField::encode(is_prefix) | TokenField::encode(op);
    1744             :   }
    1745             : 
    1746             :   class IsPrefixField
    1747             :       : public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
    1748             :   class TokenField : public BitField<Token::Value, IsPrefixField::kNext, 7> {};
    1749             : 
    1750             :   Expression* expression_;
    1751             : };
    1752             : 
    1753             : 
    1754             : class CompareOperation final : public Expression {
    1755             :  public:
    1756             :   Token::Value op() const { return OperatorField::decode(bit_field_); }
    1757             :   Expression* left() const { return left_; }
    1758             :   Expression* right() const { return right_; }
    1759             : 
    1760           0 :   void set_left(Expression* e) { left_ = e; }
    1761           0 :   void set_right(Expression* e) { right_ = e; }
    1762             : 
    1763             :   // Match special cases.
    1764             :   bool IsLiteralCompareTypeof(Expression** expr, Literal** literal);
    1765             :   bool IsLiteralCompareUndefined(Expression** expr);
    1766             :   bool IsLiteralCompareNull(Expression** expr);
    1767             : 
    1768             :  private:
    1769             :   friend class AstNodeFactory;
    1770             : 
    1771             :   CompareOperation(Token::Value op, Expression* left, Expression* right,
    1772             :                    int pos)
    1773     3235378 :       : Expression(pos, kCompareOperation), left_(left), right_(right) {
    1774     3235378 :     bit_field_ |= OperatorField::encode(op);
    1775             :     DCHECK(Token::IsCompareOp(op));
    1776             :   }
    1777             : 
    1778             :   Expression* left_;
    1779             :   Expression* right_;
    1780             : 
    1781             :   class OperatorField
    1782             :       : public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
    1783             : };
    1784             : 
    1785             : 
    1786             : class Spread final : public Expression {
    1787             :  public:
    1788        2794 :   Expression* expression() const { return expression_; }
    1789           0 :   void set_expression(Expression* e) { expression_ = e; }
    1790             : 
    1791             :   int expression_position() const { return expr_pos_; }
    1792             : 
    1793             :  private:
    1794             :   friend class AstNodeFactory;
    1795             : 
    1796             :   Spread(Expression* expression, int pos, int expr_pos)
    1797             :       : Expression(pos, kSpread),
    1798             :         expr_pos_(expr_pos),
    1799       40923 :         expression_(expression) {}
    1800             : 
    1801             :   int expr_pos_;
    1802             :   Expression* expression_;
    1803             : };
    1804             : 
    1805             : 
    1806             : class Conditional final : public Expression {
    1807             :  public:
    1808             :   Expression* condition() const { return condition_; }
    1809             :   Expression* then_expression() const { return then_expression_; }
    1810             :   Expression* else_expression() const { return else_expression_; }
    1811             : 
    1812           0 :   void set_condition(Expression* e) { condition_ = e; }
    1813           0 :   void set_then_expression(Expression* e) { then_expression_ = e; }
    1814           0 :   void set_else_expression(Expression* e) { else_expression_ = e; }
    1815             : 
    1816             :  private:
    1817             :   friend class AstNodeFactory;
    1818             : 
    1819             :   Conditional(Expression* condition, Expression* then_expression,
    1820             :               Expression* else_expression, int position)
    1821             :       : Expression(position, kConditional),
    1822             :         condition_(condition),
    1823             :         then_expression_(then_expression),
    1824      193104 :         else_expression_(else_expression) {}
    1825             : 
    1826             :   Expression* condition_;
    1827             :   Expression* then_expression_;
    1828             :   Expression* else_expression_;
    1829             : };
    1830             : 
    1831             : class Assignment : public Expression {
    1832             :  public:
    1833             :   Token::Value op() const { return TokenField::decode(bit_field_); }
    1834             :   Expression* target() const { return target_; }
    1835             :   Expression* value() const { return value_; }
    1836             : 
    1837           0 :   void set_target(Expression* e) { target_ = e; }
    1838           0 :   void set_value(Expression* e) { value_ = e; }
    1839             : 
    1840             :   // The assignment was generated as part of block-scoped sloppy-mode
    1841             :   // function hoisting, see
    1842             :   // ES#sec-block-level-function-declarations-web-legacy-compatibility-semantics
    1843             :   LookupHoistingMode lookup_hoisting_mode() const {
    1844             :     return static_cast<LookupHoistingMode>(
    1845     5038376 :         LookupHoistingModeField::decode(bit_field_));
    1846             :   }
    1847             :   void set_lookup_hoisting_mode(LookupHoistingMode mode) {
    1848             :     bit_field_ =
    1849       13356 :         LookupHoistingModeField::update(bit_field_, static_cast<bool>(mode));
    1850             :   }
    1851             : 
    1852             :  protected:
    1853             :   Assignment(NodeType type, Token::Value op, Expression* target,
    1854             :              Expression* value, int pos);
    1855             : 
    1856             :  private:
    1857             :   friend class AstNodeFactory;
    1858             : 
    1859             :   class TokenField
    1860             :       : public BitField<Token::Value, Expression::kNextBitFieldIndex, 7> {};
    1861             :   class LookupHoistingModeField : public BitField<bool, TokenField::kNext, 1> {
    1862             :   };
    1863             : 
    1864             :   Expression* target_;
    1865             :   Expression* value_;
    1866             : };
    1867             : 
    1868             : class CompoundAssignment final : public Assignment {
    1869             :  public:
    1870             :   BinaryOperation* binary_operation() const { return binary_operation_; }
    1871             : 
    1872             :  private:
    1873             :   friend class AstNodeFactory;
    1874             : 
    1875             :   CompoundAssignment(Token::Value op, Expression* target, Expression* value,
    1876             :                      int pos, BinaryOperation* binary_operation)
    1877             :       : Assignment(kCompoundAssignment, op, target, value, pos),
    1878      332182 :         binary_operation_(binary_operation) {}
    1879             : 
    1880             :   BinaryOperation* binary_operation_;
    1881             : };
    1882             : 
    1883             : // The RewritableExpression class is a wrapper for AST nodes that wait
    1884             : // for some potential rewriting.  However, even if such nodes are indeed
    1885             : // rewritten, the RewritableExpression wrapper nodes will survive in the
    1886             : // final AST and should be just ignored, i.e., they should be treated as
    1887             : // equivalent to the wrapped nodes.  For this reason and to simplify later
    1888             : // phases, RewritableExpressions are considered as exceptions of AST nodes
    1889             : // in the following sense:
    1890             : //
    1891             : // 1. IsRewritableExpression and AsRewritableExpression behave as usual.
    1892             : // 2. All other Is* and As* methods are practically delegated to the
    1893             : //    wrapped node, i.e. IsArrayLiteral() will return true iff the
    1894             : //    wrapped node is an array literal.
    1895             : //
    1896             : // Furthermore, an invariant that should be respected is that the wrapped
    1897             : // node is not a RewritableExpression.
    1898             : class RewritableExpression final : public Expression {
    1899             :  public:
    1900      359298 :   Expression* expression() const { return expr_; }
    1901      146112 :   bool is_rewritten() const { return IsRewrittenField::decode(bit_field_); }
    1902             :   void set_rewritten() {
    1903      186428 :     bit_field_ = IsRewrittenField::update(bit_field_, true);
    1904             :   }
    1905             : 
    1906             :   void Rewrite(Expression* new_expression) {
    1907             :     DCHECK(!is_rewritten());
    1908             :     DCHECK_NOT_NULL(new_expression);
    1909             :     DCHECK(!new_expression->IsRewritableExpression());
    1910       79898 :     expr_ = new_expression;
    1911             :     set_rewritten();
    1912             :   }
    1913             : 
    1914             :  private:
    1915             :   friend class AstNodeFactory;
    1916             : 
    1917             :   explicit RewritableExpression(Expression* expression)
    1918             :       : Expression(expression->position(), kRewritableExpression),
    1919      219014 :         expr_(expression) {
    1920             :     bit_field_ |= IsRewrittenField::encode(false);
    1921             :     DCHECK(!expression->IsRewritableExpression());
    1922             :   }
    1923             : 
    1924             :   Expression* expr_;
    1925             : 
    1926             :   class IsRewrittenField
    1927             :       : public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
    1928             : };
    1929             : 
    1930             : // There are several types of Suspend node:
    1931             : //
    1932             : // Yield
    1933             : // YieldStar
    1934             : // Await
    1935             : //
    1936             : // Our Yield is different from the JS yield in that it "returns" its argument as
    1937             : // is, without wrapping it in an iterator result object.  Such wrapping, if
    1938             : // desired, must be done beforehand (see the parser).
    1939             : class Suspend : public Expression {
    1940             :  public:
    1941             :   // With {kNoControl}, the {Suspend} behaves like yield, except that it never
    1942             :   // throws and never causes the current generator to return. This is used to
    1943             :   // desugar yield*.
    1944             :   // TODO(caitp): remove once yield* desugaring for async generators is handled
    1945             :   // in BytecodeGenerator.
    1946             :   enum OnAbruptResume { kOnExceptionThrow, kNoControl };
    1947             : 
    1948             :   Expression* expression() const { return expression_; }
    1949             :   OnAbruptResume on_abrupt_resume() const {
    1950             :     return OnAbruptResumeField::decode(bit_field_);
    1951             :   }
    1952             : 
    1953             :   int suspend_id() const { return suspend_id_; }
    1954             : 
    1955           0 :   void set_expression(Expression* e) { expression_ = e; }
    1956       24155 :   void set_suspend_id(int id) { suspend_id_ = id; }
    1957             : 
    1958       14283 :   inline bool IsInitialYield() const { return suspend_id_ == 0 && IsYield(); }
    1959             : 
    1960             :  private:
    1961             :   friend class AstNodeFactory;
    1962             :   friend class Yield;
    1963             :   friend class YieldStar;
    1964             :   friend class Await;
    1965             : 
    1966             :   Suspend(NodeType node_type, Expression* expression, int pos,
    1967             :           OnAbruptResume on_abrupt_resume)
    1968      177197 :       : Expression(pos, node_type), suspend_id_(-1), expression_(expression) {
    1969       84760 :     bit_field_ |= OnAbruptResumeField::encode(on_abrupt_resume);
    1970             :   }
    1971             : 
    1972             :   int suspend_id_;
    1973             :   Expression* expression_;
    1974             : 
    1975             :   class OnAbruptResumeField
    1976             :       : public BitField<OnAbruptResume, Expression::kNextBitFieldIndex, 1> {};
    1977             : };
    1978             : 
    1979             : class Yield final : public Suspend {
    1980             :  private:
    1981             :   friend class AstNodeFactory;
    1982             :   Yield(Expression* expression, int pos, OnAbruptResume on_abrupt_resume)
    1983             :       : Suspend(kYield, expression, pos, on_abrupt_resume) {}
    1984             : };
    1985             : 
    1986             : class YieldStar final : public Suspend {
    1987             :  public:
    1988             :   // In addition to the normal suspend for yield*, a yield* in an async
    1989             :   // generator has 2 additional suspends:
    1990             :   //   - One for awaiting the iterator result of closing the generator when
    1991             :   //     resumed with a "throw" completion, and a throw method is not present
    1992             :   //     on the delegated iterator (await_iterator_close_suspend_id)
    1993             :   //   - One for awaiting the iterator result yielded by the delegated iterator
    1994             :   //     (await_delegated_iterator_output_suspend_id)
    1995             :   int await_iterator_close_suspend_id() const {
    1996             :     DCHECK_NE(-1, await_iterator_close_suspend_id_);
    1997             :     return await_iterator_close_suspend_id_;
    1998             :   }
    1999             :   void set_await_iterator_close_suspend_id(int id) {
    2000          11 :     await_iterator_close_suspend_id_ = id;
    2001             :   }
    2002             : 
    2003             :   int await_delegated_iterator_output_suspend_id() const {
    2004             :     DCHECK_NE(-1, await_delegated_iterator_output_suspend_id_);
    2005             :     return await_delegated_iterator_output_suspend_id_;
    2006             :   }
    2007             :   void set_await_delegated_iterator_output_suspend_id(int id) {
    2008          11 :     await_delegated_iterator_output_suspend_id_ = id;
    2009             :   }
    2010             : 
    2011             :   inline int suspend_count() const {
    2012         243 :     if (await_iterator_close_suspend_id_ != -1) {
    2013             :       DCHECK_NE(-1, await_delegated_iterator_output_suspend_id_);
    2014             :       return 3;
    2015             :     }
    2016             :     return 1;
    2017             :   }
    2018             : 
    2019             :  private:
    2020             :   friend class AstNodeFactory;
    2021             : 
    2022             :   YieldStar(Expression* expression, int pos)
    2023             :       : Suspend(kYieldStar, expression, pos,
    2024             :                 Suspend::OnAbruptResume::kNoControl),
    2025             :         await_iterator_close_suspend_id_(-1),
    2026        2102 :         await_delegated_iterator_output_suspend_id_(-1) {}
    2027             : 
    2028             :   int await_iterator_close_suspend_id_;
    2029             :   int await_delegated_iterator_output_suspend_id_;
    2030             : };
    2031             : 
    2032             : class Await final : public Suspend {
    2033             :  private:
    2034             :   friend class AstNodeFactory;
    2035             : 
    2036             :   Await(Expression* expression, int pos)
    2037             :       : Suspend(kAwait, expression, pos, Suspend::kOnExceptionThrow) {}
    2038             : };
    2039             : 
    2040             : class Throw final : public Expression {
    2041             :  public:
    2042             :   Expression* exception() const { return exception_; }
    2043           0 :   void set_exception(Expression* e) { exception_ = e; }
    2044             : 
    2045             :  private:
    2046             :   friend class AstNodeFactory;
    2047             : 
    2048             :   Throw(Expression* exception, int pos)
    2049      407734 :       : Expression(pos, kThrow), exception_(exception) {}
    2050             : 
    2051             :   Expression* exception_;
    2052             : };
    2053             : 
    2054             : 
    2055             : class FunctionLiteral final : public Expression {
    2056             :  public:
    2057             :   enum FunctionType {
    2058             :     kAnonymousExpression,
    2059             :     kNamedExpression,
    2060             :     kDeclaration,
    2061             :     kAccessorOrMethod
    2062             :   };
    2063             : 
    2064             :   enum IdType { kIdTypeInvalid = -1, kIdTypeTopLevel = 0 };
    2065             : 
    2066             :   enum ParameterFlag { kNoDuplicateParameters, kHasDuplicateParameters };
    2067             : 
    2068             :   enum EagerCompileHint { kShouldEagerCompile, kShouldLazyCompile };
    2069             : 
    2070             :   // Empty handle means that the function does not have a shared name (i.e.
    2071             :   // the name will be set dynamically after creation of the function closure).
    2072             :   MaybeHandle<String> name() const {
    2073     5166991 :     return raw_name_ ? raw_name_->string() : MaybeHandle<String>();
    2074             :   }
    2075             :   Handle<String> name(Isolate* isolate) const;
    2076             :   bool has_shared_name() const { return raw_name_ != nullptr; }
    2077             :   const AstConsString* raw_name() const { return raw_name_; }
    2078      951269 :   void set_raw_name(const AstConsString* name) { raw_name_ = name; }
    2079             :   DeclarationScope* scope() const { return scope_; }
    2080             :   ZoneList<Statement*>* body() const { return body_; }
    2081     5691239 :   void set_function_token_position(int pos) { function_token_position_ = pos; }
    2082             :   int function_token_position() const { return function_token_position_; }
    2083             :   int start_position() const;
    2084             :   int end_position() const;
    2085    10333982 :   bool is_declaration() const { return function_type() == kDeclaration; }
    2086     5166991 :   bool is_named_expression() const {
    2087     5166991 :     return function_type() == kNamedExpression;
    2088             :   }
    2089     6717756 :   bool is_anonymous_expression() const {
    2090     5166991 :     return function_type() == kAnonymousExpression;
    2091             :   }
    2092             :   LanguageMode language_mode() const;
    2093             : 
    2094             :   static bool NeedsHomeObject(Expression* expr);
    2095             : 
    2096             :   int expected_property_count() {
    2097             :     // Not valid for lazy functions.
    2098             :     DCHECK_NOT_NULL(body_);
    2099             :     return expected_property_count_;
    2100             :   }
    2101             :   int parameter_count() { return parameter_count_; }
    2102             :   int function_length() { return function_length_; }
    2103             : 
    2104             :   bool AllowsLazyCompilation();
    2105             : 
    2106     6497139 :   bool CanSuspend() {
    2107     6497139 :     if (suspend_count() > 0) {
    2108             :       DCHECK(IsResumableFunction(kind()));
    2109             :       return true;
    2110             :     }
    2111             :     return false;
    2112             :   }
    2113             : 
    2114           0 :   Handle<String> debug_name() const {
    2115           0 :     if (raw_name_ != nullptr && !raw_name_->IsEmpty()) {
    2116             :       return raw_name_->string();
    2117             :     }
    2118           0 :     return inferred_name();
    2119             :   }
    2120             : 
    2121     5166991 :   Handle<String> inferred_name() const {
    2122     5166991 :     if (!inferred_name_.is_null()) {
    2123             :       DCHECK_NULL(raw_inferred_name_);
    2124           0 :       return inferred_name_;
    2125             :     }
    2126     5166991 :     if (raw_inferred_name_ != nullptr) {
    2127             :       return raw_inferred_name_->string();
    2128             :     }
    2129           0 :     UNREACHABLE();
    2130             :   }
    2131             : 
    2132             :   // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
    2133             :   void set_inferred_name(Handle<String> inferred_name) {
    2134             :     DCHECK(!inferred_name.is_null());
    2135      668141 :     inferred_name_ = inferred_name;
    2136             :     DCHECK(raw_inferred_name_ == nullptr || raw_inferred_name_->IsEmpty());
    2137      668141 :     raw_inferred_name_ = nullptr;
    2138             :   }
    2139             : 
    2140             :   void set_raw_inferred_name(const AstConsString* raw_inferred_name) {
    2141             :     DCHECK_NOT_NULL(raw_inferred_name);
    2142     2046259 :     raw_inferred_name_ = raw_inferred_name;
    2143             :     DCHECK(inferred_name_.is_null());
    2144     2046259 :     inferred_name_ = Handle<String>();
    2145             :   }
    2146             : 
    2147             :   bool pretenure() const { return Pretenure::decode(bit_field_); }
    2148     2464498 :   void set_pretenure() { bit_field_ = Pretenure::update(bit_field_, true); }
    2149             : 
    2150             :   bool has_duplicate_parameters() const {
    2151             :     // Not valid for lazy functions.
    2152             :     DCHECK_NOT_NULL(body_);
    2153             :     return HasDuplicateParameters::decode(bit_field_);
    2154             :   }
    2155             : 
    2156             :   // This is used as a heuristic on when to eagerly compile a function
    2157             :   // literal. We consider the following constructs as hints that the
    2158             :   // function will be called immediately:
    2159             :   // - (function() { ... })();
    2160             :   // - var x = function() { ... }();
    2161             :   bool ShouldEagerCompile() const;
    2162             :   void SetShouldEagerCompile();
    2163             : 
    2164             :   FunctionType function_type() const {
    2165             :     return FunctionTypeBits::decode(bit_field_);
    2166             :   }
    2167             :   FunctionKind kind() const;
    2168             : 
    2169             :   bool dont_optimize() { return dont_optimize_reason() != kNoReason; }
    2170             :   BailoutReason dont_optimize_reason() {
    2171             :     return DontOptimizeReasonField::decode(bit_field_);
    2172             :   }
    2173             :   void set_dont_optimize_reason(BailoutReason reason) {
    2174     4385612 :     bit_field_ = DontOptimizeReasonField::update(bit_field_, reason);
    2175             :   }
    2176             : 
    2177             :   bool IsAnonymousFunctionDefinition() const {
    2178             :     return is_anonymous_expression();
    2179             :   }
    2180             : 
    2181             :   int suspend_count() { return suspend_count_; }
    2182     2192806 :   void set_suspend_count(int suspend_count) { suspend_count_ = suspend_count; }
    2183             : 
    2184     3066219 :   int return_position() {
    2185     6132439 :     return std::max(start_position(), end_position() - (has_braces_ ? 1 : 0));
    2186             :   }
    2187             : 
    2188             :   int function_literal_id() const { return function_literal_id_; }
    2189             :   void set_function_literal_id(int function_literal_id) {
    2190         315 :     function_literal_id_ = function_literal_id;
    2191             :   }
    2192             : 
    2193             :   ProducedPreParsedScopeData* produced_preparsed_scope_data() const {
    2194             :     return produced_preparsed_scope_data_;
    2195             :   }
    2196             : 
    2197             :  private:
    2198             :   friend class AstNodeFactory;
    2199             : 
    2200     7137476 :   FunctionLiteral(
    2201     7137474 :       Zone* zone, const AstRawString* name, AstValueFactory* ast_value_factory,
    2202             :       DeclarationScope* scope, ZoneList<Statement*>* body,
    2203             :       int expected_property_count, int parameter_count, int function_length,
    2204             :       FunctionType function_type, ParameterFlag has_duplicate_parameters,
    2205             :       EagerCompileHint eager_compile_hint, int position, bool has_braces,
    2206             :       int function_literal_id,
    2207             :       ProducedPreParsedScopeData* produced_preparsed_scope_data = nullptr)
    2208             :       : Expression(position, kFunctionLiteral),
    2209             :         expected_property_count_(expected_property_count),
    2210             :         parameter_count_(parameter_count),
    2211             :         function_length_(function_length),
    2212             :         function_token_position_(kNoSourcePosition),
    2213             :         suspend_count_(0),
    2214             :         has_braces_(has_braces),
    2215             :         raw_name_(name ? ast_value_factory->NewConsString(name) : nullptr),
    2216             :         scope_(scope),
    2217             :         body_(body),
    2218             :         raw_inferred_name_(ast_value_factory->empty_cons_string()),
    2219             :         function_literal_id_(function_literal_id),
    2220    21412424 :         produced_preparsed_scope_data_(produced_preparsed_scope_data) {
    2221             :     bit_field_ |= FunctionTypeBits::encode(function_type) |
    2222     7137474 :                   Pretenure::encode(false) |
    2223             :                   HasDuplicateParameters::encode(has_duplicate_parameters ==
    2224     7137474 :                                                  kHasDuplicateParameters) |
    2225     7137474 :                   DontOptimizeReasonField::encode(kNoReason);
    2226     7137474 :     if (eager_compile_hint == kShouldEagerCompile) SetShouldEagerCompile();
    2227             :     DCHECK_EQ(body == nullptr, expected_property_count < 0);
    2228     7137475 :   }
    2229             : 
    2230             :   class FunctionTypeBits
    2231             :       : public BitField<FunctionType, Expression::kNextBitFieldIndex, 2> {};
    2232             :   class Pretenure : public BitField<bool, FunctionTypeBits::kNext, 1> {};
    2233             :   class HasDuplicateParameters : public BitField<bool, Pretenure::kNext, 1> {};
    2234             :   class DontOptimizeReasonField
    2235             :       : public BitField<BailoutReason, HasDuplicateParameters::kNext, 8> {};
    2236             : 
    2237             :   int expected_property_count_;
    2238             :   int parameter_count_;
    2239             :   int function_length_;
    2240             :   int function_token_position_;
    2241             :   int suspend_count_;
    2242             :   bool has_braces_;
    2243             : 
    2244             :   const AstConsString* raw_name_;
    2245             :   DeclarationScope* scope_;
    2246             :   ZoneList<Statement*>* body_;
    2247             :   const AstConsString* raw_inferred_name_;
    2248             :   Handle<String> inferred_name_;
    2249             :   int function_literal_id_;
    2250             :   ProducedPreParsedScopeData* produced_preparsed_scope_data_;
    2251             : };
    2252             : 
    2253             : // Property is used for passing information
    2254             : // about a class literal's properties from the parser to the code generator.
    2255             : class ClassLiteralProperty final : public LiteralProperty {
    2256             :  public:
    2257             :   enum Kind : uint8_t { METHOD, GETTER, SETTER, FIELD };
    2258             : 
    2259             :   Kind kind() const { return kind_; }
    2260             : 
    2261             :   bool is_static() const { return is_static_; }
    2262             : 
    2263             :  private:
    2264             :   friend class AstNodeFactory;
    2265             : 
    2266             :   ClassLiteralProperty(Expression* key, Expression* value, Kind kind,
    2267             :                        bool is_static, bool is_computed_name);
    2268             : 
    2269             :   Kind kind_;
    2270             :   bool is_static_;
    2271             : };
    2272             : 
    2273             : class ClassLiteral final : public Expression {
    2274             :  public:
    2275             :   typedef ClassLiteralProperty Property;
    2276             : 
    2277             :   Scope* scope() const { return scope_; }
    2278             :   Variable* class_variable() const { return class_variable_; }
    2279             :   Expression* extends() const { return extends_; }
    2280           0 :   void set_extends(Expression* e) { extends_ = e; }
    2281             :   FunctionLiteral* constructor() const { return constructor_; }
    2282           0 :   void set_constructor(FunctionLiteral* f) { constructor_ = f; }
    2283             :   ZoneList<Property*>* properties() const { return properties_; }
    2284       59344 :   int start_position() const { return position(); }
    2285             :   int end_position() const { return end_position_; }
    2286             :   bool has_name_static_property() const {
    2287             :     return HasNameStaticProperty::decode(bit_field_);
    2288             :   }
    2289             :   bool has_static_computed_names() const {
    2290             :     return HasStaticComputedNames::decode(bit_field_);
    2291             :   }
    2292             : 
    2293             :   bool is_anonymous_expression() const {
    2294             :     return IsAnonymousExpression::decode(bit_field_);
    2295             :   }
    2296        3588 :   bool IsAnonymousFunctionDefinition() const {
    2297             :     return is_anonymous_expression();
    2298             :   }
    2299             : 
    2300             :  private:
    2301             :   friend class AstNodeFactory;
    2302             : 
    2303             :   ClassLiteral(Scope* scope, Variable* class_variable, Expression* extends,
    2304             :                FunctionLiteral* constructor, ZoneList<Property*>* properties,
    2305             :                int start_position, int end_position,
    2306             :                bool has_name_static_property, bool has_static_computed_names,
    2307             :                bool is_anonymous)
    2308             :       : Expression(start_position, kClassLiteral),
    2309             :         end_position_(end_position),
    2310             :         scope_(scope),
    2311             :         class_variable_(class_variable),
    2312             :         extends_(extends),
    2313             :         constructor_(constructor),
    2314      111783 :         properties_(properties) {
    2315      111783 :     bit_field_ |= HasNameStaticProperty::encode(has_name_static_property) |
    2316             :                   HasStaticComputedNames::encode(has_static_computed_names) |
    2317      111783 :                   IsAnonymousExpression::encode(is_anonymous);
    2318             :   }
    2319             : 
    2320             :   int end_position_;
    2321             :   Scope* scope_;
    2322             :   Variable* class_variable_;
    2323             :   Expression* extends_;
    2324             :   FunctionLiteral* constructor_;
    2325             :   ZoneList<Property*>* properties_;
    2326             : 
    2327             :   class HasNameStaticProperty
    2328             :       : public BitField<bool, Expression::kNextBitFieldIndex, 1> {};
    2329             :   class HasStaticComputedNames
    2330             :       : public BitField<bool, HasNameStaticProperty::kNext, 1> {};
    2331             :   class IsAnonymousExpression
    2332             :       : public BitField<bool, HasStaticComputedNames::kNext, 1> {};
    2333             : };
    2334             : 
    2335             : 
    2336             : class NativeFunctionLiteral final : public Expression {
    2337             :  public:
    2338        1678 :   Handle<String> name() const { return name_->string(); }
    2339             :   v8::Extension* extension() const { return extension_; }
    2340             : 
    2341             :  private:
    2342             :   friend class AstNodeFactory;
    2343             : 
    2344             :   NativeFunctionLiteral(const AstRawString* name, v8::Extension* extension,
    2345             :                         int pos)
    2346             :       : Expression(pos, kNativeFunctionLiteral),
    2347             :         name_(name),
    2348        1678 :         extension_(extension) {}
    2349             : 
    2350             :   const AstRawString* name_;
    2351             :   v8::Extension* extension_;
    2352             : };
    2353             : 
    2354             : 
    2355             : class ThisFunction final : public Expression {
    2356             :  private:
    2357             :   friend class AstNodeFactory;
    2358             :   explicit ThisFunction(int pos) : Expression(pos, kThisFunction) {}
    2359             : };
    2360             : 
    2361             : 
    2362             : class SuperPropertyReference final : public Expression {
    2363             :  public:
    2364             :   VariableProxy* this_var() const { return this_var_; }
    2365           0 :   void set_this_var(VariableProxy* v) { this_var_ = v; }
    2366             :   Expression* home_object() const { return home_object_; }
    2367           0 :   void set_home_object(Expression* e) { home_object_ = e; }
    2368             : 
    2369             :  private:
    2370             :   friend class AstNodeFactory;
    2371             : 
    2372             :   SuperPropertyReference(VariableProxy* this_var, Expression* home_object,
    2373             :                          int pos)
    2374             :       : Expression(pos, kSuperPropertyReference),
    2375             :         this_var_(this_var),
    2376        2814 :         home_object_(home_object) {
    2377             :     DCHECK(this_var->is_this());
    2378             :     DCHECK(home_object->IsProperty());
    2379             :   }
    2380             : 
    2381             :   VariableProxy* this_var_;
    2382             :   Expression* home_object_;
    2383             : };
    2384             : 
    2385             : 
    2386             : class SuperCallReference final : public Expression {
    2387             :  public:
    2388             :   VariableProxy* this_var() const { return this_var_; }
    2389           0 :   void set_this_var(VariableProxy* v) { this_var_ = v; }
    2390             :   VariableProxy* new_target_var() const { return new_target_var_; }
    2391           0 :   void set_new_target_var(VariableProxy* v) { new_target_var_ = v; }
    2392             :   VariableProxy* this_function_var() const { return this_function_var_; }
    2393           0 :   void set_this_function_var(VariableProxy* v) { this_function_var_ = v; }
    2394             : 
    2395             :  private:
    2396             :   friend class AstNodeFactory;
    2397             : 
    2398             :   SuperCallReference(VariableProxy* this_var, VariableProxy* new_target_var,
    2399             :                      VariableProxy* this_function_var, int pos)
    2400             :       : Expression(pos, kSuperCallReference),
    2401             :         this_var_(this_var),
    2402             :         new_target_var_(new_target_var),
    2403       16531 :         this_function_var_(this_function_var) {
    2404             :     DCHECK(this_var->is_this());
    2405             :     DCHECK(new_target_var->raw_name()->IsOneByteEqualTo(".new.target"));
    2406             :     DCHECK(this_function_var->raw_name()->IsOneByteEqualTo(".this_function"));
    2407             :   }
    2408             : 
    2409             :   VariableProxy* this_var_;
    2410             :   VariableProxy* new_target_var_;
    2411             :   VariableProxy* this_function_var_;
    2412             : };
    2413             : 
    2414             : // This AST Node is used to represent a dynamic import call --
    2415             : // import(argument).
    2416             : class ImportCallExpression final : public Expression {
    2417             :  public:
    2418             :   Expression* argument() const { return argument_; }
    2419           0 :   void set_argument(Expression* argument) { argument_ = argument; }
    2420             : 
    2421             :  private:
    2422             :   friend class AstNodeFactory;
    2423             : 
    2424             :   ImportCallExpression(Expression* argument, int pos)
    2425         872 :       : Expression(pos, kImportCallExpression), argument_(argument) {}
    2426             : 
    2427             :   Expression* argument_;
    2428             : };
    2429             : 
    2430             : // This class is produced when parsing the () in arrow functions without any
    2431             : // arguments and is not actually a valid expression.
    2432             : class EmptyParentheses final : public Expression {
    2433             :  private:
    2434             :   friend class AstNodeFactory;
    2435             : 
    2436             :   explicit EmptyParentheses(int pos) : Expression(pos, kEmptyParentheses) {}
    2437             : };
    2438             : 
    2439             : // Represents the spec operation `GetIterator()`
    2440             : // (defined at https://tc39.github.io/ecma262/#sec-getiterator). Ignition
    2441             : // desugars this into a LoadIC / JSLoadNamed, CallIC, and a type-check to
    2442             : // validate return value of the Symbol.iterator() call.
    2443             : enum class IteratorType { kNormal, kAsync };
    2444             : class GetIterator final : public Expression {
    2445             :  public:
    2446             :   IteratorType hint() const { return hint_; }
    2447             : 
    2448             :   Expression* iterable() const { return iterable_; }
    2449           0 :   void set_iterable(Expression* iterable) { iterable_ = iterable; }
    2450             : 
    2451             :   Expression* iterable_for_call_printer() const {
    2452             :     return destructured_iterable_ != nullptr ? destructured_iterable_
    2453        1763 :                                              : iterable_;
    2454             :   }
    2455             : 
    2456             :  private:
    2457             :   friend class AstNodeFactory;
    2458             : 
    2459             :   GetIterator(Expression* iterable, Expression* destructured_iterable,
    2460             :               IteratorType hint, int pos)
    2461             :       : Expression(pos, kGetIterator),
    2462             :         hint_(hint),
    2463             :         iterable_(iterable),
    2464       65280 :         destructured_iterable_(destructured_iterable) {}
    2465             : 
    2466             :   GetIterator(Expression* iterable, IteratorType hint, int pos)
    2467             :       : Expression(pos, kGetIterator),
    2468             :         hint_(hint),
    2469             :         iterable_(iterable),
    2470      103232 :         destructured_iterable_(nullptr) {}
    2471             : 
    2472             :   IteratorType hint_;
    2473             :   Expression* iterable_;
    2474             : 
    2475             :   // iterable_ is the variable proxy, while destructured_iterable_ points to
    2476             :   // the raw value stored in the variable proxy. This is only used for
    2477             :   // pretty printing error messages.
    2478             :   Expression* destructured_iterable_;
    2479             : };
    2480             : 
    2481             : // Represents the spec operation `GetTemplateObject(templateLiteral)`
    2482             : // (defined at https://tc39.github.io/ecma262/#sec-gettemplateobject).
    2483             : class GetTemplateObject final : public Expression {
    2484             :  public:
    2485             :   ZoneList<Literal*>* cooked_strings() const { return cooked_strings_; }
    2486             :   ZoneList<Literal*>* raw_strings() const { return raw_strings_; }
    2487             :   int hash() const { return hash_; }
    2488             : 
    2489             :   Handle<TemplateObjectDescription> GetOrBuildDescription(Isolate* isolate);
    2490             : 
    2491             :  private:
    2492             :   friend class AstNodeFactory;
    2493             : 
    2494             :   GetTemplateObject(ZoneList<Literal*>* cooked_strings,
    2495             :                     ZoneList<Literal*>* raw_strings, int hash, int pos)
    2496             :       : Expression(pos, kGetTemplateObject),
    2497             :         cooked_strings_(cooked_strings),
    2498             :         raw_strings_(raw_strings),
    2499        6818 :         hash_(hash) {}
    2500             : 
    2501             :   ZoneList<Literal*>* cooked_strings_;
    2502             :   ZoneList<Literal*>* raw_strings_;
    2503             :   int hash_;
    2504             : };
    2505             : 
    2506             : // ----------------------------------------------------------------------------
    2507             : // Basic visitor
    2508             : // Sub-class should parametrize AstVisitor with itself, e.g.:
    2509             : //   class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... }
    2510             : 
    2511             : template <class Subclass>
    2512             : class AstVisitor BASE_EMBEDDED {
    2513             :  public:
    2514             :   void Visit(AstNode* node) { impl()->Visit(node); }
    2515             : 
    2516             :   void VisitDeclarations(Declaration::List* declarations) {
    2517             :     for (Declaration* decl : *declarations) Visit(decl);
    2518             :   }
    2519             : 
    2520             :   void VisitStatements(ZoneList<Statement*>* statements) {
    2521             :     for (int i = 0; i < statements->length(); i++) {
    2522             :       Statement* stmt = statements->at(i);
    2523             :       Visit(stmt);
    2524             :       if (stmt->IsJump()) break;
    2525             :     }
    2526             :   }
    2527             : 
    2528             :   void VisitExpressions(ZoneList<Expression*>* expressions) {
    2529             :     for (int i = 0; i < expressions->length(); i++) {
    2530             :       // The variable statement visiting code may pass null expressions
    2531             :       // to this code. Maybe this should be handled by introducing an
    2532             :       // undefined expression or literal? Revisit this code if this
    2533             :       // changes.
    2534             :       Expression* expression = expressions->at(i);
    2535             :       if (expression != nullptr) Visit(expression);
    2536             :     }
    2537             :   }
    2538             : 
    2539             :  protected:
    2540             :   Subclass* impl() { return static_cast<Subclass*>(this); }
    2541             : };
    2542             : 
    2543             : #define GENERATE_VISIT_CASE(NodeType)                                   \
    2544             :   case AstNode::k##NodeType:                                            \
    2545             :     return this->impl()->Visit##NodeType(static_cast<NodeType*>(node));
    2546             : 
    2547             : #define GENERATE_AST_VISITOR_SWITCH()  \
    2548             :   switch (node->node_type()) {         \
    2549             :     AST_NODE_LIST(GENERATE_VISIT_CASE) \
    2550             :   }
    2551             : 
    2552             : #define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS()               \
    2553             :  public:                                                    \
    2554             :   void VisitNoStackOverflowCheck(AstNode* node) {           \
    2555             :     GENERATE_AST_VISITOR_SWITCH()                           \
    2556             :   }                                                         \
    2557             :                                                             \
    2558             :   void Visit(AstNode* node) {                               \
    2559             :     if (CheckStackOverflow()) return;                       \
    2560             :     VisitNoStackOverflowCheck(node);                        \
    2561             :   }                                                         \
    2562             :                                                             \
    2563             :   void SetStackOverflow() { stack_overflow_ = true; }       \
    2564             :   void ClearStackOverflow() { stack_overflow_ = false; }    \
    2565             :   bool HasStackOverflow() const { return stack_overflow_; } \
    2566             :                                                             \
    2567             :   bool CheckStackOverflow() {                               \
    2568             :     if (stack_overflow_) return true;                       \
    2569             :     if (GetCurrentStackPosition() < stack_limit_) {         \
    2570             :       stack_overflow_ = true;                               \
    2571             :       return true;                                          \
    2572             :     }                                                       \
    2573             :     return false;                                           \
    2574             :   }                                                         \
    2575             :                                                             \
    2576             :  private:                                                   \
    2577             :   void InitializeAstVisitor(Isolate* isolate) {             \
    2578             :     stack_limit_ = isolate->stack_guard()->real_climit();   \
    2579             :     stack_overflow_ = false;                                \
    2580             :   }                                                         \
    2581             :                                                             \
    2582             :   void InitializeAstVisitor(uintptr_t stack_limit) {        \
    2583             :     stack_limit_ = stack_limit;                             \
    2584             :     stack_overflow_ = false;                                \
    2585             :   }                                                         \
    2586             :                                                             \
    2587             :   uintptr_t stack_limit_;                                   \
    2588             :   bool stack_overflow_
    2589             : 
    2590             : #define DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()    \
    2591             :  public:                                                      \
    2592             :   void Visit(AstNode* node) { GENERATE_AST_VISITOR_SWITCH() } \
    2593             :                                                               \
    2594             :  private:
    2595             : 
    2596             : #define DEFINE_AST_REWRITER_SUBCLASS_MEMBERS()        \
    2597             :  public:                                              \
    2598             :   AstNode* Rewrite(AstNode* node) {                   \
    2599             :     DCHECK_NULL(replacement_);                        \
    2600             :     DCHECK_NOT_NULL(node);                            \
    2601             :     Visit(node);                                      \
    2602             :     if (HasStackOverflow()) return node;              \
    2603             :     if (replacement_ == nullptr) return node;         \
    2604             :     AstNode* result = replacement_;                   \
    2605             :     replacement_ = nullptr;                           \
    2606             :     return result;                                    \
    2607             :   }                                                   \
    2608             :                                                       \
    2609             :  private:                                             \
    2610             :   void InitializeAstRewriter(Isolate* isolate) {      \
    2611             :     InitializeAstVisitor(isolate);                    \
    2612             :     replacement_ = nullptr;                           \
    2613             :   }                                                   \
    2614             :                                                       \
    2615             :   void InitializeAstRewriter(uintptr_t stack_limit) { \
    2616             :     InitializeAstVisitor(stack_limit);                \
    2617             :     replacement_ = nullptr;                           \
    2618             :   }                                                   \
    2619             :                                                       \
    2620             :   DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();              \
    2621             :                                                       \
    2622             :  protected:                                           \
    2623             :   AstNode* replacement_
    2624             : // Generic macro for rewriting things; `GET` is the expression to be
    2625             : // rewritten; `SET` is a command that should do the rewriting, i.e.
    2626             : // something sensible with the variable called `replacement`.
    2627             : #define AST_REWRITE(Type, GET, SET)                            \
    2628             :   do {                                                         \
    2629             :     DCHECK(!HasStackOverflow());                               \
    2630             :     DCHECK_NULL(replacement_);                                 \
    2631             :     Visit(GET);                                                \
    2632             :     if (HasStackOverflow()) return;                            \
    2633             :     if (replacement_ == nullptr) break;                        \
    2634             :     Type* replacement = reinterpret_cast<Type*>(replacement_); \
    2635             :     do {                                                       \
    2636             :       SET;                                                     \
    2637             :     } while (false);                                           \
    2638             :     replacement_ = nullptr;                                    \
    2639             :   } while (false)
    2640             : 
    2641             : // Macro for rewriting object properties; it assumes that `object` has
    2642             : // `property` with a public getter and setter.
    2643             : #define AST_REWRITE_PROPERTY(Type, object, property)                        \
    2644             :   do {                                                                      \
    2645             :     auto _obj = (object);                                                   \
    2646             :     AST_REWRITE(Type, _obj->property(), _obj->set_##property(replacement)); \
    2647             :   } while (false)
    2648             : 
    2649             : // Macro for rewriting list elements; it assumes that `list` has methods
    2650             : // `at` and `Set`.
    2651             : #define AST_REWRITE_LIST_ELEMENT(Type, list, index)                        \
    2652             :   do {                                                                     \
    2653             :     auto _list = (list);                                                   \
    2654             :     auto _index = (index);                                                 \
    2655             :     AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \
    2656             :   } while (false)
    2657             : 
    2658             : 
    2659             : // ----------------------------------------------------------------------------
    2660             : // AstNode factory
    2661             : 
    2662             : class AstNodeFactory final BASE_EMBEDDED {
    2663             :  public:
    2664             :   AstNodeFactory(AstValueFactory* ast_value_factory, Zone* zone)
    2665    10204311 :       : zone_(zone), ast_value_factory_(ast_value_factory) {}
    2666             : 
    2667             :   AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
    2668             : 
    2669      102482 :   VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, int pos) {
    2670      204964 :     return new (zone_) VariableDeclaration(proxy, pos);
    2671             :   }
    2672             : 
    2673             :   NestedVariableDeclaration* NewNestedVariableDeclaration(VariableProxy* proxy,
    2674             :                                                           Scope* scope,
    2675             :                                                           int pos) {
    2676             :     return new (zone_) NestedVariableDeclaration(proxy, scope, pos);
    2677             :   }
    2678             : 
    2679             :   FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
    2680             :                                               FunctionLiteral* fun, int pos) {
    2681             :     return new (zone_) FunctionDeclaration(proxy, fun, pos);
    2682             :   }
    2683             : 
    2684    14189395 :   Block* NewBlock(int capacity, bool ignore_completion_value,
    2685             :                   ZoneList<const AstRawString*>* labels = nullptr) {
    2686             :     return labels != nullptr
    2687             :                ? new (zone_) LabeledBlock(zone_, labels, capacity,
    2688       12940 :                                           ignore_completion_value)
    2689             :                : new (zone_)
    2690    42555241 :                      Block(zone_, labels, capacity, ignore_completion_value);
    2691             :   }
    2692             : 
    2693             : #define STATEMENT_WITH_LABELS(NodeType)                                     \
    2694             :   NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
    2695             :     return new (zone_) NodeType(labels, pos);                               \
    2696             :   }
    2697       13654 :   STATEMENT_WITH_LABELS(DoWhileStatement)
    2698      139846 :   STATEMENT_WITH_LABELS(WhileStatement)
    2699      917826 :   STATEMENT_WITH_LABELS(ForStatement)
    2700             : #undef STATEMENT_WITH_LABELS
    2701             : 
    2702       20224 :   SwitchStatement* NewSwitchStatement(ZoneList<const AstRawString*>* labels,
    2703             :                                       Expression* tag, int pos) {
    2704       60672 :     return new (zone_) SwitchStatement(zone_, labels, tag, pos);
    2705             :   }
    2706             : 
    2707      137732 :   ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
    2708             :                                         ZoneList<const AstRawString*>* labels,
    2709             :                                         int pos) {
    2710      137732 :     switch (visit_mode) {
    2711             :       case ForEachStatement::ENUMERATE: {
    2712       53682 :         return new (zone_) ForInStatement(labels, pos);
    2713             :       }
    2714             :       case ForEachStatement::ITERATE: {
    2715       84050 :         return new (zone_) ForOfStatement(labels, pos);
    2716             :       }
    2717             :     }
    2718           0 :     UNREACHABLE();
    2719             :   }
    2720             : 
    2721       34299 :   ForOfStatement* NewForOfStatement(ZoneList<const AstRawString*>* labels,
    2722             :                                     int pos) {
    2723       68598 :     return new (zone_) ForOfStatement(labels, pos);
    2724             :   }
    2725             : 
    2726      220170 :   ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
    2727      440340 :     return new (zone_) ExpressionStatement(expression, pos);
    2728             :   }
    2729             : 
    2730             :   ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
    2731             :     return new (zone_) ContinueStatement(target, pos);
    2732             :   }
    2733             : 
    2734             :   BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
    2735             :     return new (zone_) BreakStatement(target, pos);
    2736             :   }
    2737             : 
    2738       28512 :   ReturnStatement* NewReturnStatement(Expression* expression, int pos,
    2739             :                                       int end_position = kNoSourcePosition) {
    2740             :     return new (zone_) ReturnStatement(expression, ReturnStatement::kNormal,
    2741       57024 :                                        pos, end_position);
    2742             :   }
    2743             : 
    2744             :   ReturnStatement* NewAsyncReturnStatement(
    2745             :       Expression* expression, int pos, int end_position = kNoSourcePosition) {
    2746             :     return new (zone_) ReturnStatement(
    2747             :         expression, ReturnStatement::kAsyncReturn, pos, end_position);
    2748             :   }
    2749             : 
    2750             :   WithStatement* NewWithStatement(Scope* scope,
    2751             :                                   Expression* expression,
    2752             :                                   Statement* statement,
    2753             :                                   int pos) {
    2754             :     return new (zone_) WithStatement(scope, expression, statement, pos);
    2755             :   }
    2756             : 
    2757             :   IfStatement* NewIfStatement(Expression* condition, Statement* then_statement,
    2758             :                               Statement* else_statement, int pos) {
    2759             :     return new (zone_)
    2760             :         IfStatement(condition, then_statement, else_statement, pos);
    2761             :   }
    2762             : 
    2763             :   TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope,
    2764             :                                           Block* catch_block, int pos) {
    2765             :     return new (zone_) TryCatchStatement(try_block, scope, catch_block,
    2766             :                                          HandlerTable::CAUGHT, pos);
    2767             :   }
    2768             : 
    2769             :   TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block,
    2770             :                                                     Scope* scope,
    2771             :                                                     Block* catch_block,
    2772             :                                                     int pos) {
    2773             :     return new (zone_) TryCatchStatement(try_block, scope, catch_block,
    2774             :                                          HandlerTable::UNCAUGHT, pos);
    2775             :   }
    2776             : 
    2777             :   TryCatchStatement* NewTryCatchStatementForDesugaring(Block* try_block,
    2778             :                                                        Scope* scope,
    2779             :                                                        Block* catch_block,
    2780             :                                                        int pos) {
    2781             :     return new (zone_) TryCatchStatement(try_block, scope, catch_block,
    2782             :                                          HandlerTable::DESUGARING, pos);
    2783             :   }
    2784             : 
    2785             :   TryCatchStatement* NewTryCatchStatementForAsyncAwait(Block* try_block,
    2786             :                                                        Scope* scope,
    2787             :                                                        Block* catch_block,
    2788             :                                                        int pos) {
    2789             :     return new (zone_) TryCatchStatement(try_block, scope, catch_block,
    2790             :                                          HandlerTable::ASYNC_AWAIT, pos);
    2791             :   }
    2792             : 
    2793             :   TryFinallyStatement* NewTryFinallyStatement(Block* try_block,
    2794             :                                               Block* finally_block, int pos) {
    2795             :     return new (zone_) TryFinallyStatement(try_block, finally_block, pos);
    2796             :   }
    2797             : 
    2798             :   DebuggerStatement* NewDebuggerStatement(int pos) {
    2799             :     return new (zone_) DebuggerStatement(pos);
    2800             :   }
    2801             : 
    2802             :   EmptyStatement* NewEmptyStatement(int pos) {
    2803             :     return new (zone_) EmptyStatement(pos);
    2804             :   }
    2805             : 
    2806        8566 :   SloppyBlockFunctionStatement* NewSloppyBlockFunctionStatement() {
    2807             :     return new (zone_)
    2808       17132 :         SloppyBlockFunctionStatement(NewEmptyStatement(kNoSourcePosition));
    2809             :   }
    2810             : 
    2811             :   CaseClause* NewCaseClause(Expression* label,
    2812             :                             ZoneList<Statement*>* statements) {
    2813      109361 :     return new (zone_) CaseClause(label, statements);
    2814             :   }
    2815             : 
    2816    20054299 :   Literal* NewStringLiteral(const AstRawString* string, int pos) {
    2817    40108580 :     return new (zone_) Literal(ast_value_factory_->NewString(string), pos);
    2818             :   }
    2819             : 
    2820             :   // A JavaScript symbol (ECMA-262 edition 6).
    2821        2814 :   Literal* NewSymbolLiteral(AstSymbol symbol, int pos) {
    2822        5628 :     return new (zone_) Literal(ast_value_factory_->NewSymbol(symbol), pos);
    2823             :   }
    2824             : 
    2825     3652502 :   Literal* NewNumberLiteral(double number, int pos) {
    2826     7305004 :     return new (zone_) Literal(ast_value_factory_->NewNumber(number), pos);
    2827             :   }
    2828             : 
    2829    20530525 :   Literal* NewSmiLiteral(uint32_t number, int pos) {
    2830    41061050 :     return new (zone_) Literal(ast_value_factory_->NewSmi(number), pos);
    2831             :   }
    2832             : 
    2833          25 :   Literal* NewBigIntLiteral(const char* buffer, int pos) {
    2834          50 :     return new (zone_) Literal(ast_value_factory_->NewBigInt(buffer), pos);
    2835             :   }
    2836             : 
    2837      969518 :   Literal* NewBooleanLiteral(bool b, int pos) {
    2838     1939036 :     return new (zone_) Literal(ast_value_factory_->NewBoolean(b), pos);
    2839             :   }
    2840             : 
    2841      455717 :   Literal* NewNullLiteral(int pos) {
    2842      911434 :     return new (zone_) Literal(ast_value_factory_->NewNull(), pos);
    2843             :   }
    2844             : 
    2845      667290 :   Literal* NewUndefinedLiteral(int pos) {
    2846     1334580 :     return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos);
    2847             :   }
    2848             : 
    2849     1173912 :   Literal* NewTheHoleLiteral() {
    2850             :     return new (zone_)
    2851     2347824 :         Literal(ast_value_factory_->NewTheHole(), kNoSourcePosition);
    2852             :   }
    2853             : 
    2854      761229 :   ObjectLiteral* NewObjectLiteral(
    2855             :       ZoneList<ObjectLiteral::Property*>* properties,
    2856             :       uint32_t boilerplate_properties, int pos, bool has_rest_property) {
    2857             :     return new (zone_) ObjectLiteral(properties, boilerplate_properties, pos,
    2858     1522458 :                                      has_rest_property);
    2859             :   }
    2860             : 
    2861             :   ObjectLiteral::Property* NewObjectLiteralProperty(
    2862             :       Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
    2863             :       bool is_computed_name) {
    2864             :     return new (zone_)
    2865      106057 :         ObjectLiteral::Property(key, value, kind, is_computed_name);
    2866             :   }
    2867             : 
    2868     3651363 :   ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
    2869             :                                                     Expression* value,
    2870             :                                                     bool is_computed_name) {
    2871             :     return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
    2872     7302725 :                                                is_computed_name);
    2873             :   }
    2874             : 
    2875             :   RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags,
    2876             :                                   int pos) {
    2877             :     return new (zone_) RegExpLiteral(pattern, flags, pos);
    2878             :   }
    2879             : 
    2880             :   ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
    2881             :                                 int pos) {
    2882             :     return new (zone_) ArrayLiteral(values, -1, pos);
    2883             :   }
    2884             : 
    2885             :   ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
    2886             :                                 int first_spread_index, int pos) {
    2887             :     return new (zone_) ArrayLiteral(values, first_spread_index, pos);
    2888             :   }
    2889             : 
    2890       11478 :   VariableProxy* NewVariableProxy(Variable* var,
    2891             :                                   int start_position = kNoSourcePosition) {
    2892     9029803 :     return new (zone_) VariableProxy(var, start_position);
    2893             :   }
    2894             : 
    2895   104008491 :   VariableProxy* NewVariableProxy(const AstRawString* name,
    2896             :                                   VariableKind variable_kind,
    2897             :                                   int start_position = kNoSourcePosition) {
    2898             :     DCHECK_NOT_NULL(name);
    2899   208016981 :     return new (zone_) VariableProxy(name, variable_kind, start_position);
    2900             :   }
    2901             : 
    2902             :   // Recreates the VariableProxy in this Zone.
    2903             :   VariableProxy* CopyVariableProxy(VariableProxy* proxy) {
    2904     5058783 :     return new (zone_) VariableProxy(proxy);
    2905             :   }
    2906             : 
    2907             :   Variable* CopyVariable(Variable* variable) {
    2908      580769 :     return new (zone_) Variable(variable);
    2909             :   }
    2910             : 
    2911         126 :   Property* NewProperty(Expression* obj, Expression* key, int pos) {
    2912         252 :     return new (zone_) Property(obj, key, pos);
    2913             :   }
    2914             : 
    2915             :   Call* NewCall(Expression* expression, ZoneList<Expression*>* arguments,
    2916             :                 int pos, Call::PossiblyEval possibly_eval = Call::NOT_EVAL) {
    2917             :     return new (zone_) Call(expression, arguments, pos, possibly_eval);
    2918             :   }
    2919             : 
    2920             :   Call* NewTaggedTemplate(Expression* expression,
    2921             :                           ZoneList<Expression*>* arguments, int pos) {
    2922             :     return new (zone_)
    2923             :         Call(expression, arguments, pos, Call::TaggedTemplateTag::kTrue);
    2924             :   }
    2925             : 
    2926             :   CallNew* NewCallNew(Expression* expression,
    2927             :                       ZoneList<Expression*>* arguments,
    2928             :                       int pos) {
    2929             :     return new (zone_) CallNew(expression, arguments, pos);
    2930             :   }
    2931             : 
    2932     1556393 :   CallRuntime* NewCallRuntime(Runtime::FunctionId id,
    2933             :                               ZoneList<Expression*>* arguments, int pos) {
    2934     3112786 :     return new (zone_) CallRuntime(Runtime::FunctionForId(id), arguments, pos);
    2935             :   }
    2936             : 
    2937      957818 :   CallRuntime* NewCallRuntime(const Runtime::Function* function,
    2938             :                               ZoneList<Expression*>* arguments, int pos) {
    2939     1915636 :     return new (zone_) CallRuntime(function, arguments, pos);
    2940             :   }
    2941             : 
    2942      142632 :   CallRuntime* NewCallRuntime(int context_index,
    2943             :                               ZoneList<Expression*>* arguments, int pos) {
    2944      285264 :     return new (zone_) CallRuntime(context_index, arguments, pos);
    2945             :   }
    2946             : 
    2947             :   UnaryOperation* NewUnaryOperation(Token::Value op,
    2948             :                                     Expression* expression,
    2949             :                                     int pos) {
    2950             :     return new (zone_) UnaryOperation(op, expression, pos);
    2951             :   }
    2952             : 
    2953          40 :   BinaryOperation* NewBinaryOperation(Token::Value op,
    2954             :                                       Expression* left,
    2955             :                                       Expression* right,
    2956             :                                       int pos) {
    2957          80 :     return new (zone_) BinaryOperation(op, left, right, pos);
    2958             :   }
    2959             : 
    2960          86 :   CountOperation* NewCountOperation(Token::Value op,
    2961             :                                     bool is_prefix,
    2962             :                                     Expression* expr,
    2963             :                                     int pos) {
    2964         172 :     return new (zone_) CountOperation(op, is_prefix, expr, pos);
    2965             :   }
    2966             : 
    2967             :   CompareOperation* NewCompareOperation(Token::Value op,
    2968             :                                         Expression* left,
    2969             :                                         Expression* right,
    2970             :                                         int pos) {
    2971             :     return new (zone_) CompareOperation(op, left, right, pos);
    2972             :   }
    2973             : 
    2974             :   Spread* NewSpread(Expression* expression, int pos, int expr_pos) {
    2975             :     return new (zone_) Spread(expression, pos, expr_pos);
    2976             :   }
    2977             : 
    2978             :   Conditional* NewConditional(Expression* condition,
    2979             :                               Expression* then_expression,
    2980             :                               Expression* else_expression,
    2981             :                               int position) {
    2982             :     return new (zone_)
    2983             :         Conditional(condition, then_expression, else_expression, position);
    2984             :   }
    2985             : 
    2986             :   RewritableExpression* NewRewritableExpression(Expression* expression) {
    2987             :     DCHECK_NOT_NULL(expression);
    2988             :     return new (zone_) RewritableExpression(expression);
    2989             :   }
    2990             : 
    2991    17152764 :   Assignment* NewAssignment(Token::Value op,
    2992             :                             Expression* target,
    2993             :                             Expression* value,
    2994      332182 :                             int pos) {
    2995             :     DCHECK(Token::IsAssignmentOp(op));
    2996             : 
    2997    26649217 :     if (op != Token::INIT && target->IsVariableProxy()) {
    2998     5458658 :       target->AsVariableProxy()->set_is_assigned();
    2999             :     }
    3000             : 
    3001    17152765 :     if (op == Token::ASSIGN || op == Token::INIT) {
    3002             :       return new (zone_)
    3003    33641164 :           Assignment(AstNode::kAssignment, op, target, value, pos);
    3004             :     } else {
    3005             :       return new (zone_) CompoundAssignment(
    3006             :           op, target, value, pos,
    3007             :           NewBinaryOperation(Token::BinaryOpForAssignment(op), target, value,
    3008      996546 :                              pos + 1));
    3009             :     }
    3010             :   }
    3011             : 
    3012       82658 :   Suspend* NewYield(Expression* expression, int pos,
    3013             :                     Suspend::OnAbruptResume on_abrupt_resume) {
    3014       82658 :     if (!expression) expression = NewUndefinedLiteral(pos);
    3015      165316 :     return new (zone_) Yield(expression, pos, on_abrupt_resume);
    3016             :   }
    3017             : 
    3018        2102 :   YieldStar* NewYieldStar(Expression* expression, int pos) {
    3019             :     DCHECK_NOT_NULL(expression);
    3020        4204 :     return new (zone_) YieldStar(expression, pos);
    3021             :   }
    3022             : 
    3023       92437 :   Await* NewAwait(Expression* expression, int pos) {
    3024       92437 :     if (!expression) expression = NewUndefinedLiteral(pos);
    3025      184874 :     return new (zone_) Await(expression, pos);
    3026             :   }
    3027             : 
    3028      138724 :   Throw* NewThrow(Expression* exception, int pos) {
    3029      277448 :     return new (zone_) Throw(exception, pos);
    3030             :   }
    3031             : 
    3032     5775019 :   FunctionLiteral* NewFunctionLiteral(
    3033             :       const AstRawString* name, DeclarationScope* scope,
    3034             :       ZoneList<Statement*>* body, int expected_property_count,
    3035             :       int parameter_count, int function_length,
    3036             :       FunctionLiteral::ParameterFlag has_duplicate_parameters,
    3037             :       FunctionLiteral::FunctionType function_type,
    3038             :       FunctionLiteral::EagerCompileHint eager_compile_hint, int position,
    3039             :       bool has_braces, int function_literal_id,
    3040             :       ProducedPreParsedScopeData* produced_preparsed_scope_data = nullptr) {
    3041             :     return new (zone_) FunctionLiteral(
    3042             :         zone_, name, ast_value_factory_, scope, body, expected_property_count,
    3043             :         parameter_count, function_length, function_type,
    3044             :         has_duplicate_parameters, eager_compile_hint, position, has_braces,
    3045    11550038 :         function_literal_id, produced_preparsed_scope_data);
    3046             :   }
    3047             : 
    3048             :   // Creates a FunctionLiteral representing a top-level script, the
    3049             :   // result of an eval (top-level or otherwise), or the result of calling
    3050             :   // the Function constructor.
    3051     1362457 :   FunctionLiteral* NewScriptOrEvalFunctionLiteral(DeclarationScope* scope,
    3052             :                                                   ZoneList<Statement*>* body,
    3053             :                                                   int expected_property_count,
    3054             :                                                   int parameter_count) {
    3055             :     return new (zone_) FunctionLiteral(
    3056     1362457 :         zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
    3057             :         body, expected_property_count, parameter_count, parameter_count,
    3058             :         FunctionLiteral::kAnonymousExpression,
    3059             :         FunctionLiteral::kNoDuplicateParameters,
    3060             :         FunctionLiteral::kShouldLazyCompile, 0, true,
    3061     2724914 :         FunctionLiteral::kIdTypeTopLevel);
    3062             :   }
    3063             : 
    3064             :   ClassLiteral::Property* NewClassLiteralProperty(
    3065             :       Expression* key, Expression* value, ClassLiteralProperty::Kind kind,
    3066             :       bool is_static, bool is_computed_name) {
    3067             :     return new (zone_)
    3068      472919 :         ClassLiteral::Property(key, value, kind, is_static, is_computed_name);
    3069             :   }
    3070             : 
    3071      111783 :   ClassLiteral* NewClassLiteral(Scope* scope, Variable* variable,
    3072             :                                 Expression* extends,
    3073             :                                 FunctionLiteral* constructor,
    3074             :                                 ZoneList<ClassLiteral::Property*>* properties,
    3075             :                                 int start_position, int end_position,
    3076             :                                 bool has_name_static_property,
    3077             :                                 bool has_static_computed_names,
    3078             :                                 bool is_anonymous) {
    3079             :     return new (zone_)
    3080             :         ClassLiteral(scope, variable, extends, constructor, properties,
    3081             :                      start_position, end_position, has_name_static_property,
    3082      223566 :                      has_static_computed_names, is_anonymous);
    3083             :   }
    3084             : 
    3085        1678 :   NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
    3086             :                                                   v8::Extension* extension,
    3087             :                                                   int pos) {
    3088        3356 :     return new (zone_) NativeFunctionLiteral(name, extension, pos);
    3089             :   }
    3090             : 
    3091       80510 :   DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) {
    3092             :     VariableProxy* result = NewVariableProxy(result_var, pos);
    3093      161020 :     return new (zone_) DoExpression(block, result, pos);
    3094             :   }
    3095             : 
    3096             :   ThisFunction* NewThisFunction(int pos) {
    3097             :     return new (zone_) ThisFunction(pos);
    3098             :   }
    3099             : 
    3100             :   SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var,
    3101             :                                                     Expression* home_object,
    3102             :                                                     int pos) {
    3103             :     return new (zone_) SuperPropertyReference(this_var, home_object, pos);
    3104             :   }
    3105             : 
    3106             :   SuperCallReference* NewSuperCallReference(VariableProxy* this_var,
    3107             :                                             VariableProxy* new_target_var,
    3108             :                                             VariableProxy* this_function_var,
    3109             :                                             int pos) {
    3110             :     return new (zone_)
    3111             :         SuperCallReference(this_var, new_target_var, this_function_var, pos);
    3112             :   }
    3113             : 
    3114             :   EmptyParentheses* NewEmptyParentheses(int pos) {
    3115             :     return new (zone_) EmptyParentheses(pos);
    3116             :   }
    3117             : 
    3118             :   GetIterator* NewGetIterator(Expression* iterable,
    3119             :                               Expression* destructured_iterable,
    3120             :                               IteratorType hint, int pos) {
    3121             :     return new (zone_) GetIterator(iterable, destructured_iterable, hint, pos);
    3122             :   }
    3123             : 
    3124             :   GetIterator* NewGetIterator(Expression* iterable, IteratorType hint,
    3125             :                               int pos) {
    3126             :     return new (zone_) GetIterator(iterable, hint, pos);
    3127             :   }
    3128             : 
    3129             :   GetTemplateObject* NewGetTemplateObject(ZoneList<Literal*>* cooked_strings,
    3130             :                                           ZoneList<Literal*>* raw_strings,
    3131             :                                           int hash, int pos) {
    3132             :     return new (zone_)
    3133             :         GetTemplateObject(cooked_strings, raw_strings, hash, pos);
    3134             :   }
    3135             : 
    3136             :   ImportCallExpression* NewImportCallExpression(Expression* args, int pos) {
    3137             :     return new (zone_) ImportCallExpression(args, pos);
    3138             :   }
    3139             : 
    3140             :   Zone* zone() const { return zone_; }
    3141    11665585 :   void set_zone(Zone* zone) { zone_ = zone; }
    3142             : 
    3143             :  private:
    3144             :   // This zone may be deallocated upon returning from parsing a function body
    3145             :   // which we can guarantee is not going to be compiled or have its AST
    3146             :   // inspected.
    3147             :   // See ParseFunctionLiteral in parser.cc for preconditions.
    3148             :   Zone* zone_;
    3149             :   AstValueFactory* ast_value_factory_;
    3150             : };
    3151             : 
    3152             : 
    3153             : // Type testing & conversion functions overridden by concrete subclasses.
    3154             : // Inline functions for AstNode.
    3155             : 
    3156             : #define DECLARE_NODE_FUNCTIONS(type)                                         \
    3157             :   bool AstNode::Is##type() const {                                           \
    3158             :     NodeType mine = node_type();                                             \
    3159             :     if (mine == AstNode::kRewritableExpression &&                            \
    3160             :         AstNode::k##type != AstNode::kRewritableExpression)                  \
    3161             :       mine = reinterpret_cast<const RewritableExpression*>(this)             \
    3162             :                  ->expression()                                              \
    3163             :                  ->node_type();                                              \
    3164             :     return mine == AstNode::k##type;                                         \
    3165             :   }                                                                          \
    3166             :   type* AstNode::As##type() {                                                \
    3167             :     NodeType mine = node_type();                                             \
    3168             :     AstNode* result = this;                                                  \
    3169             :     if (mine == AstNode::kRewritableExpression &&                            \
    3170             :         AstNode::k##type != AstNode::kRewritableExpression) {                \
    3171             :       result =                                                               \
    3172             :           reinterpret_cast<const RewritableExpression*>(this)->expression(); \
    3173             :       mine = result->node_type();                                            \
    3174             :     }                                                                        \
    3175             :     return mine == AstNode::k##type ? reinterpret_cast<type*>(result)        \
    3176             :                                     : nullptr;                               \
    3177             :   }                                                                          \
    3178             :   const type* AstNode::As##type() const {                                    \
    3179             :     NodeType mine = node_type();                                             \
    3180             :     const AstNode* result = this;                                            \
    3181             :     if (mine == AstNode::kRewritableExpression &&                            \
    3182             :         AstNode::k##type != AstNode::kRewritableExpression) {                \
    3183             :       result =                                                               \
    3184             :           reinterpret_cast<const RewritableExpression*>(this)->expression(); \
    3185             :       mine = result->node_type();                                            \
    3186             :     }                                                                        \
    3187             :     return mine == AstNode::k##type ? reinterpret_cast<const type*>(result)  \
    3188             :                                     : nullptr;                               \
    3189             :   }
    3190   799306905 : AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
    3191             : #undef DECLARE_NODE_FUNCTIONS
    3192             : 
    3193             : }  // namespace internal
    3194             : }  // namespace v8
    3195             : 
    3196             : #endif  // V8_AST_AST_H_

Generated by: LCOV version 1.10