LCOV - code coverage report
Current view: top level - src/parsing - parser.h (source / functions) Hit Total Coverage
Test: app.info Lines: 160 161 99.4 %
Date: 2019-01-20 Functions: 13 13 100.0 %

          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_PARSING_PARSER_H_
       6             : #define V8_PARSING_PARSER_H_
       7             : 
       8             : #include <cstddef>
       9             : 
      10             : #include "src/ast/ast-source-ranges.h"
      11             : #include "src/ast/ast.h"
      12             : #include "src/ast/scopes.h"
      13             : #include "src/base/compiler-specific.h"
      14             : #include "src/base/threaded-list.h"
      15             : #include "src/globals.h"
      16             : #include "src/parsing/parser-base.h"
      17             : #include "src/parsing/parsing.h"
      18             : #include "src/parsing/preparser.h"
      19             : #include "src/pointer-with-payload.h"
      20             : #include "src/zone/zone-chunk-list.h"
      21             : 
      22             : namespace v8 {
      23             : 
      24             : class ScriptCompiler;
      25             : 
      26             : namespace internal {
      27             : 
      28             : class ConsumedPreparseData;
      29             : class ParseInfo;
      30             : class ParserTarget;
      31             : class ParserTargetScope;
      32             : class PendingCompilationErrorHandler;
      33             : class PreparseData;
      34             : 
      35             : class FunctionEntry {
      36             :  public:
      37             :   enum {
      38             :     kStartPositionIndex,
      39             :     kEndPositionIndex,
      40             :     kNumParametersIndex,
      41             :     kFlagsIndex,
      42             :     kNumInnerFunctionsIndex,
      43             :     kSize
      44             :   };
      45             : 
      46             :   explicit FunctionEntry(Vector<unsigned> backing)
      47             :     : backing_(backing) { }
      48             : 
      49             :   FunctionEntry() : backing_() { }
      50             : 
      51             :   class LanguageModeField : public BitField<LanguageMode, 0, 1> {};
      52             :   class UsesSuperPropertyField
      53             :       : public BitField<bool, LanguageModeField::kNext, 1> {};
      54             : 
      55             :   static uint32_t EncodeFlags(LanguageMode language_mode,
      56             :                               bool uses_super_property) {
      57             :     return LanguageModeField::encode(language_mode) |
      58             :            UsesSuperPropertyField::encode(uses_super_property);
      59             :   }
      60             : 
      61             :   int start_pos() const { return backing_[kStartPositionIndex]; }
      62             :   int end_pos() const { return backing_[kEndPositionIndex]; }
      63             :   int num_parameters() const { return backing_[kNumParametersIndex]; }
      64             :   LanguageMode language_mode() const {
      65             :     return LanguageModeField::decode(backing_[kFlagsIndex]);
      66             :   }
      67             :   bool uses_super_property() const {
      68             :     return UsesSuperPropertyField::decode(backing_[kFlagsIndex]);
      69             :   }
      70             :   int num_inner_functions() const { return backing_[kNumInnerFunctionsIndex]; }
      71             : 
      72             :   bool is_valid() const { return !backing_.is_empty(); }
      73             : 
      74             :  private:
      75             :   Vector<unsigned> backing_;
      76             : };
      77             : 
      78             : 
      79             : // ----------------------------------------------------------------------------
      80             : // JAVASCRIPT PARSING
      81             : 
      82             : class Parser;
      83             : 
      84             : 
      85             : struct ParserFormalParameters : FormalParametersBase {
      86             :   struct Parameter : public ZoneObject {
      87     4022957 :     Parameter(Expression* pattern, Expression* initializer, int position,
      88             :               int initializer_end_position, bool is_rest)
      89             :         : initializer_and_is_rest(initializer, is_rest),
      90             :           pattern(pattern),
      91             :           position(position),
      92     4022957 :           initializer_end_position(initializer_end_position) {}
      93             : 
      94             :     PointerWithPayload<Expression, bool, 1> initializer_and_is_rest;
      95             : 
      96             :     Expression* pattern;
      97     2840702 :     Expression* initializer() const {
      98     2840702 :       return initializer_and_is_rest.GetPointer();
      99             :     }
     100             :     int position;
     101             :     int initializer_end_position;
     102     5681408 :     inline bool is_rest() const { return initializer_and_is_rest.GetPayload(); }
     103             : 
     104             :     Parameter* next_parameter = nullptr;
     105       56824 :     bool is_simple() const {
     106      181593 :       return pattern->IsVariableProxy() && initializer() == nullptr &&
     107       56823 :              !is_rest();
     108             :     }
     109             : 
     110     5521295 :     const AstRawString* name() const {
     111             :       DCHECK(is_simple());
     112    11042602 :       return pattern->AsVariableProxy()->raw_name();
     113             :     }
     114             : 
     115             :     Parameter** next() { return &next_parameter; }
     116             :     Parameter* const* next() const { return &next_parameter; }
     117             :   };
     118             : 
     119             :   void set_strict_parameter_error(const Scanner::Location& loc,
     120             :                                   MessageTemplate message) {
     121      374836 :     strict_error_loc = loc;
     122      374836 :     strict_error_message = message;
     123             :   }
     124             : 
     125     5524170 :   bool has_duplicate() const { return duplicate_loc.IsValid(); }
     126             :   void ValidateDuplicate(Parser* parser) const;
     127             :   void ValidateStrictMode(Parser* parser) const;
     128             : 
     129             :   explicit ParserFormalParameters(DeclarationScope* scope)
     130     1847969 :       : FormalParametersBase(scope) {}
     131             : 
     132             :   base::ThreadedList<Parameter> params;
     133             :   Scanner::Location duplicate_loc = Scanner::Location::invalid();
     134             :   Scanner::Location strict_error_loc = Scanner::Location::invalid();
     135             :   MessageTemplate strict_error_message = MessageTemplate::kNone;
     136             : };
     137             : 
     138             : template <>
     139             : struct ParserTypes<Parser> {
     140             :   typedef ParserBase<Parser> Base;
     141             :   typedef Parser Impl;
     142             : 
     143             :   // Return types for traversing functions.
     144             :   typedef v8::internal::Block* Block;
     145             :   typedef v8::internal::BreakableStatement* BreakableStatement;
     146             :   typedef ClassLiteral::Property* ClassLiteralProperty;
     147             :   typedef ZonePtrList<ClassLiteral::Property>* ClassPropertyList;
     148             :   typedef v8::internal::Expression* Expression;
     149             :   typedef ScopedPtrList<v8::internal::Expression> ExpressionList;
     150             :   typedef ParserFormalParameters FormalParameters;
     151             :   typedef v8::internal::ForStatement* ForStatement;
     152             :   typedef v8::internal::FunctionLiteral* FunctionLiteral;
     153             :   typedef const AstRawString* Identifier;
     154             :   typedef v8::internal::IterationStatement* IterationStatement;
     155             :   typedef ObjectLiteral::Property* ObjectLiteralProperty;
     156             :   typedef ScopedPtrList<v8::internal::ObjectLiteralProperty> ObjectPropertyList;
     157             :   typedef v8::internal::Statement* Statement;
     158             :   typedef ScopedPtrList<v8::internal::Statement> StatementList;
     159             :   typedef v8::internal::Suspend* Suspend;
     160             : 
     161             :   // For constructing objects returned by the traversing functions.
     162             :   typedef AstNodeFactory Factory;
     163             : 
     164             :   // Other implementation-specific functions.
     165             :   typedef v8::internal::FuncNameInferrer FuncNameInferrer;
     166             :   typedef v8::internal::SourceRange SourceRange;
     167             :   typedef v8::internal::SourceRangeScope SourceRangeScope;
     168             :   typedef ParserTarget Target;
     169             :   typedef ParserTargetScope TargetScope;
     170             : };
     171             : 
     172             : class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
     173             :  public:
     174             :   explicit Parser(ParseInfo* info);
     175     4882121 :   ~Parser() {
     176     2842018 :     delete reusable_preparser_;
     177     2441059 :     reusable_preparser_ = nullptr;
     178     2441065 :   }
     179             : 
     180             :   static bool IsPreParser() { return false; }
     181             : 
     182             :   void ParseOnBackground(ParseInfo* info);
     183             : 
     184             :   // Initializes an empty scope chain for top-level scripts, or scopes which
     185             :   // consist of only the native context.
     186             :   void InitializeEmptyScopeChain(ParseInfo* info);
     187             : 
     188             :   // Deserialize the scope chain prior to parsing in which the script is going
     189             :   // to be executed. If the script is a top-level script, or the scope chain
     190             :   // consists of only a native context, maybe_outer_scope_info should be an
     191             :   // empty handle.
     192             :   //
     193             :   // This only deserializes the scope chain, but doesn't connect the scopes to
     194             :   // their corresponding scope infos. Therefore, looking up variables in the
     195             :   // deserialized scopes is not possible.
     196             :   void DeserializeScopeChain(Isolate* isolate, ParseInfo* info,
     197             :                              MaybeHandle<ScopeInfo> maybe_outer_scope_info,
     198             :                              Scope::DeserializationMode mode =
     199             :                                  Scope::DeserializationMode::kScopesOnly);
     200             : 
     201             :   // Move statistics to Isolate
     202             :   void UpdateStatistics(Isolate* isolate, Handle<Script> script);
     203             :   void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
     204             : 
     205             :  private:
     206             :   friend class ParserBase<Parser>;
     207             :   friend struct ParserFormalParameters;
     208             :   friend class i::ExpressionScope<ParserTypes<Parser>>;
     209             :   friend bool v8::internal::parsing::ParseProgram(ParseInfo*, Isolate*);
     210             :   friend bool v8::internal::parsing::ParseFunction(
     211             :       ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*);
     212             : 
     213             :   bool AllowsLazyParsingWithoutUnresolvedVariables() const {
     214             :     return scope()->AllowsLazyParsingWithoutUnresolvedVariables(
     215     4066745 :         original_scope_);
     216             :   }
     217             : 
     218             :   bool parse_lazily() const { return mode_ == PARSE_LAZILY; }
     219             :   enum Mode { PARSE_LAZILY, PARSE_EAGERLY };
     220             : 
     221             :   class ParsingModeScope {
     222             :    public:
     223             :     ParsingModeScope(Parser* parser, Mode mode)
     224     3718690 :         : parser_(parser), old_mode_(parser->mode_) {
     225     3718690 :       parser_->mode_ = mode;
     226             :     }
     227     3718664 :     ~ParsingModeScope() { parser_->mode_ = old_mode_; }
     228             : 
     229             :    private:
     230             :     Parser* parser_;
     231             :     Mode old_mode_;
     232             :   };
     233             : 
     234             :   // Runtime encoding of different completion modes.
     235             :   enum CompletionKind {
     236             :     kNormalCompletion,
     237             :     kThrowCompletion,
     238             :     kAbruptCompletion
     239             :   };
     240             : 
     241             :   Variable* NewTemporary(const AstRawString* name) {
     242      153499 :     return scope()->NewTemporary(name);
     243             :   }
     244             : 
     245             :   void PrepareGeneratorVariables();
     246             : 
     247             :   // Returns nullptr if parsing failed.
     248             :   FunctionLiteral* ParseProgram(Isolate* isolate, ParseInfo* info);
     249             : 
     250             :   FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info,
     251             :                                  Handle<SharedFunctionInfo> shared_info);
     252             :   FunctionLiteral* DoParseFunction(Isolate* isolate, ParseInfo* info,
     253             :                                    const AstRawString* raw_name);
     254             : 
     255             :   // Called by ParseProgram after setting up the scanner.
     256             :   FunctionLiteral* DoParseProgram(Isolate* isolate, ParseInfo* info);
     257             : 
     258             :   // Parse with the script as if the source is implicitly wrapped in a function.
     259             :   // We manually construct the AST and scopes for a top-level function and the
     260             :   // function wrapper.
     261             :   void ParseWrapped(Isolate* isolate, ParseInfo* info,
     262             :                     ScopedPtrList<Statement>* body, DeclarationScope* scope,
     263             :                     Zone* zone);
     264             : 
     265             :   ZonePtrList<const AstRawString>* PrepareWrappedArguments(Isolate* isolate,
     266             :                                                            ParseInfo* info,
     267             :                                                            Zone* zone);
     268             : 
     269     7229782 :   PreParser* reusable_preparser() {
     270     7229782 :     if (reusable_preparser_ == nullptr) {
     271             :       reusable_preparser_ = new PreParser(
     272     3207389 :           &preparser_zone_, &scanner_, stack_limit_, ast_value_factory(),
     273             :           pending_error_handler(), runtime_call_stats_, logger_, -1,
     274      801725 :           parsing_module_, parsing_on_main_thread_);
     275             : #define SET_ALLOW(name) reusable_preparser_->set_allow_##name(allow_##name());
     276             :       SET_ALLOW(natives);
     277      400944 :       SET_ALLOW(harmony_public_fields);
     278      400944 :       SET_ALLOW(harmony_static_fields);
     279      400944 :       SET_ALLOW(harmony_dynamic_import);
     280      400944 :       SET_ALLOW(harmony_import_meta);
     281      400944 :       SET_ALLOW(harmony_private_fields);
     282      400944 :       SET_ALLOW(harmony_private_methods);
     283      400944 :       SET_ALLOW(eval_cache);
     284             : #undef SET_ALLOW
     285      400944 :       preparse_data_buffer_.reserve(128);
     286             :     }
     287     7229909 :     return reusable_preparser_;
     288             :   }
     289             : 
     290             :   void ParseModuleItemList(ScopedPtrList<Statement>* body);
     291             :   Statement* ParseModuleItem();
     292             :   const AstRawString* ParseModuleSpecifier();
     293             :   void ParseImportDeclaration();
     294             :   Statement* ParseExportDeclaration();
     295             :   Statement* ParseExportDefault();
     296             :   void ParseExportStar();
     297             :   struct ExportClauseData {
     298             :     const AstRawString* export_name;
     299             :     const AstRawString* local_name;
     300             :     Scanner::Location location;
     301             :   };
     302             :   ZoneChunkList<ExportClauseData>* ParseExportClause(
     303             :       Scanner::Location* reserved_loc);
     304             :   struct NamedImport : public ZoneObject {
     305             :     const AstRawString* import_name;
     306             :     const AstRawString* local_name;
     307             :     const Scanner::Location location;
     308             :     NamedImport(const AstRawString* import_name, const AstRawString* local_name,
     309             :                 Scanner::Location location)
     310             :         : import_name(import_name),
     311             :           local_name(local_name),
     312        1139 :           location(location) {}
     313             :   };
     314             :   ZonePtrList<const NamedImport>* ParseNamedImports(int pos);
     315             :   Statement* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
     316             :                                       ZonePtrList<const AstRawString>* names);
     317             :   void DeclareLabel(ZonePtrList<const AstRawString>** labels,
     318             :                     ZonePtrList<const AstRawString>** own_labels,
     319             :                     VariableProxy* expr);
     320             :   bool ContainsLabel(ZonePtrList<const AstRawString>* labels,
     321             :                      const AstRawString* label);
     322             :   Expression* RewriteReturn(Expression* return_value, int pos);
     323             :   Statement* RewriteSwitchStatement(SwitchStatement* switch_statement,
     324             :                                     Scope* scope);
     325             :   Block* RewriteCatchPattern(CatchInfo* catch_info);
     326             :   void ReportVarRedeclarationIn(const AstRawString* name, Scope* scope);
     327             :   Statement* RewriteTryStatement(Block* try_block, Block* catch_block,
     328             :                                  const SourceRange& catch_range,
     329             :                                  Block* finally_block,
     330             :                                  const SourceRange& finally_range,
     331             :                                  const CatchInfo& catch_info, int pos);
     332             :   void GetUnexpectedTokenMessage(Token::Value token, MessageTemplate* message,
     333             :                                  Scanner::Location* location, const char** arg);
     334             :   void ParseAndRewriteGeneratorFunctionBody(int pos, FunctionKind kind,
     335             :                                             ScopedPtrList<Statement>* body);
     336             :   void ParseAndRewriteAsyncGeneratorFunctionBody(
     337             :       int pos, FunctionKind kind, ScopedPtrList<Statement>* body);
     338             :   void DeclareFunctionNameVar(const AstRawString* function_name,
     339             :                               FunctionLiteral::FunctionType function_type,
     340             :                               DeclarationScope* function_scope);
     341             : 
     342             :   Statement* DeclareFunction(const AstRawString* variable_name,
     343             :                              FunctionLiteral* function, VariableMode mode,
     344             :                              int beg_pos, int end_pos,
     345             :                              bool is_sloppy_block_function,
     346             :                              ZonePtrList<const AstRawString>* names);
     347             :   Variable* CreateSyntheticContextVariable(const AstRawString* synthetic_name);
     348             :   FunctionLiteral* CreateInitializerFunction(
     349             :       const char* name, DeclarationScope* scope,
     350             :       ZonePtrList<ClassLiteral::Property>* fields);
     351             : 
     352             :   bool IdentifierEquals(const AstRawString* identifier,
     353             :                         const AstRawString* other) {
     354             :     return identifier == other;
     355             :   }
     356             : 
     357             :   Statement* DeclareClass(const AstRawString* variable_name, Expression* value,
     358             :                           ZonePtrList<const AstRawString>* names,
     359             :                           int class_token_pos, int end_pos);
     360             :   void DeclareClassVariable(const AstRawString* name, ClassInfo* class_info,
     361             :                             int class_token_pos);
     362             :   void DeclareClassProperty(const AstRawString* class_name,
     363             :                             ClassLiteralProperty* property, bool is_constructor,
     364             :                             ClassInfo* class_info);
     365             :   void DeclareClassField(ClassLiteralProperty* property,
     366             :                          const AstRawString* property_name, bool is_static,
     367             :                          bool is_computed_name, bool is_private,
     368             :                          ClassInfo* class_info);
     369             :   Expression* RewriteClassLiteral(Scope* block_scope, const AstRawString* name,
     370             :                                   ClassInfo* class_info, int pos, int end_pos);
     371             :   Statement* DeclareNative(const AstRawString* name, int pos);
     372             : 
     373             :   Block* IgnoreCompletion(Statement* statement);
     374             : 
     375             :   Scope* NewHiddenCatchScope();
     376             : 
     377             :   // PatternRewriter and associated methods defined in pattern-rewriter.cc.
     378             :   friend class PatternRewriter;
     379             :   void InitializeVariables(
     380             :       ScopedPtrList<Statement>* statements,
     381             :       const DeclarationDescriptor* declaration_descriptor,
     382             :       const DeclarationParsingResult::Declaration* declaration,
     383             :       ZonePtrList<const AstRawString>* names);
     384             : 
     385             :   Block* RewriteForVarInLegacy(const ForInfo& for_info);
     386             :   void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block,
     387             :                                         Expression** each_variable);
     388             :   Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info);
     389             : 
     390             :   Statement* DesugarLexicalBindingsInForStatement(
     391             :       ForStatement* loop, Statement* init, Expression* cond, Statement* next,
     392             :       Statement* body, Scope* inner_scope, const ForInfo& for_info);
     393             : 
     394             :   FunctionLiteral* ParseFunctionLiteral(
     395             :       const AstRawString* name, Scanner::Location function_name_location,
     396             :       FunctionNameValidity function_name_validity, FunctionKind kind,
     397             :       int function_token_position, FunctionLiteral::FunctionType type,
     398             :       LanguageMode language_mode,
     399             :       ZonePtrList<const AstRawString>* arguments_for_wrapped_function);
     400             : 
     401             :   ObjectLiteral* InitializeObjectLiteral(ObjectLiteral* object_literal) {
     402      580409 :     object_literal->CalculateEmitStore(main_zone());
     403             :     return object_literal;
     404             :   }
     405             : 
     406             :   // Check if the scope has conflicting var/let declarations from different
     407             :   // scopes. This covers for example
     408             :   //
     409             :   // function f() { { { var x; } let x; } }
     410             :   // function g() { { var x; let x; } }
     411             :   //
     412             :   // The var declarations are hoisted to the function scope, but originate from
     413             :   // a scope where the name has also been let bound or the var declaration is
     414             :   // hoisted over such a scope.
     415             :   void CheckConflictingVarDeclarations(Scope* scope);
     416             : 
     417             :   bool IsPropertyWithPrivateFieldKey(Expression* property);
     418             : 
     419             :   // Insert initializer statements for var-bindings shadowing parameter bindings
     420             :   // from a non-simple parameter list.
     421             :   void InsertShadowingVarBindingInitializers(Block* block);
     422             : 
     423             :   // Implement sloppy block-scoped functions, ES2015 Annex B 3.3
     424             :   void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope);
     425             : 
     426             :   VariableProxy* NewUnresolved(const AstRawString* name, int begin_pos,
     427             :                                VariableKind kind = NORMAL_VARIABLE);
     428             :   VariableProxy* NewUnresolved(const AstRawString* name);
     429             :   VariableProxy* DeclareVariable(const AstRawString* name, VariableMode mode,
     430             :                                  int pos);
     431             :   VariableProxy* DeclareVariable(const AstRawString* name, VariableMode mode,
     432             :                                  InitializationFlag init, int pos);
     433             :   void DeclareVariable(VariableProxy* proxy, VariableKind kind,
     434             :                        VariableMode mode, InitializationFlag init,
     435             :                        Scope* declaration_scope, int begin,
     436             :                        int end = kNoSourcePosition);
     437             :   void Declare(Declaration* declaration, VariableProxy* proxy,
     438             :                VariableKind kind, VariableMode mode, InitializationFlag init,
     439             :                Scope* declaration_scope, int var_end_pos = kNoSourcePosition);
     440             : 
     441             :   bool TargetStackContainsLabel(const AstRawString* label);
     442             :   BreakableStatement* LookupBreakTarget(const AstRawString* label);
     443             :   IterationStatement* LookupContinueTarget(const AstRawString* label);
     444             : 
     445             :   Statement* BuildAssertIsCoercible(Variable* var, ObjectLiteral* pattern);
     446             : 
     447             :   // Factory methods.
     448             :   FunctionLiteral* DefaultConstructor(const AstRawString* name, bool call_super,
     449             :                                       int pos, int end_pos);
     450             : 
     451             :   // Skip over a lazy function, either using cached data if we have it, or
     452             :   // by parsing the function with PreParser. Consumes the ending }.
     453             :   // In case the preparser detects an error it cannot identify, it resets the
     454             :   // scanner- and preparser state to the initial one, before PreParsing the
     455             :   // function.
     456             :   // SkipFunction returns true if it correctly parsed the function, including
     457             :   // cases where we detect an error. It returns false, if we needed to stop
     458             :   // parsing or could not identify an error correctly, meaning the caller needs
     459             :   // to fully reparse. In this case it resets the scanner and preparser state.
     460             :   bool SkipFunction(const AstRawString* function_name, FunctionKind kind,
     461             :                     FunctionLiteral::FunctionType function_type,
     462             :                     DeclarationScope* function_scope, int* num_parameters,
     463             :                     ProducedPreparseData** produced_preparsed_scope_data);
     464             : 
     465             :   Block* BuildParameterInitializationBlock(
     466             :       const ParserFormalParameters& parameters);
     467             :   Block* BuildRejectPromiseOnException(Block* block);
     468             : 
     469             :   void ParseFunction(
     470             :       ScopedPtrList<Statement>* body, const AstRawString* function_name,
     471             :       int pos, FunctionKind kind, FunctionLiteral::FunctionType function_type,
     472             :       DeclarationScope* function_scope, int* num_parameters,
     473             :       int* function_length, bool* has_duplicate_parameters,
     474             :       int* expected_property_count, int* suspend_count,
     475             :       ZonePtrList<const AstRawString>* arguments_for_wrapped_function);
     476             : 
     477             :   void ThrowPendingError(Isolate* isolate, Handle<Script> script);
     478             : 
     479             :   class TemplateLiteral : public ZoneObject {
     480             :    public:
     481       38639 :     TemplateLiteral(Zone* zone, int pos)
     482       38639 :         : cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
     483             : 
     484             :     const ZonePtrList<const AstRawString>* cooked() const { return &cooked_; }
     485             :     const ZonePtrList<const AstRawString>* raw() const { return &raw_; }
     486             :     const ZonePtrList<Expression>* expressions() const { return &expressions_; }
     487             :     int position() const { return pos_; }
     488             : 
     489             :     void AddTemplateSpan(const AstRawString* cooked, const AstRawString* raw,
     490             :                          int end, Zone* zone) {
     491             :       DCHECK_NOT_NULL(raw);
     492       83841 :       cooked_.Add(cooked, zone);
     493       83840 :       raw_.Add(raw, zone);
     494             :     }
     495             : 
     496             :     void AddExpression(Expression* expression, Zone* zone) {
     497       48298 :       expressions_.Add(expression, zone);
     498             :     }
     499             : 
     500             :    private:
     501             :     ZonePtrList<const AstRawString> cooked_;
     502             :     ZonePtrList<const AstRawString> raw_;
     503             :     ZonePtrList<Expression> expressions_;
     504             :     int pos_;
     505             :   };
     506             : 
     507             :   typedef TemplateLiteral* TemplateLiteralState;
     508             : 
     509             :   TemplateLiteralState OpenTemplateLiteral(int pos);
     510             :   // "should_cook" means that the span can be "cooked": in tagged template
     511             :   // literals, both the raw and "cooked" representations are available to user
     512             :   // code ("cooked" meaning that escape sequences are converted to their
     513             :   // interpreted values). Invalid escape sequences cause the cooked span
     514             :   // to be represented by undefined, instead of being a syntax error.
     515             :   // "tail" indicates that this span is the last in the literal.
     516             :   void AddTemplateSpan(TemplateLiteralState* state, bool should_cook,
     517             :                        bool tail);
     518             :   void AddTemplateExpression(TemplateLiteralState* state,
     519             :                              Expression* expression);
     520             :   Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
     521             :                                    Expression* tag);
     522             : 
     523             :   ArrayLiteral* ArrayLiteralFromListWithSpread(
     524             :       const ScopedPtrList<Expression>& list);
     525             :   Expression* SpreadCall(Expression* function,
     526             :                          const ScopedPtrList<Expression>& args, int pos,
     527             :                          Call::PossiblyEval is_possibly_eval);
     528             :   Expression* SpreadCallNew(Expression* function,
     529             :                             const ScopedPtrList<Expression>& args, int pos);
     530             :   Expression* RewriteSuperCall(Expression* call_expression);
     531             : 
     532             :   void SetLanguageMode(Scope* scope, LanguageMode mode);
     533             :   void SetAsmModule();
     534             : 
     535             :   Expression* RewriteSpreads(ArrayLiteral* lit);
     536             : 
     537             :   friend class InitializerRewriter;
     538             :   void RewriteParameterInitializer(Expression* expr);
     539             : 
     540             :   Expression* BuildInitialYield(int pos, FunctionKind kind);
     541             :   Assignment* BuildCreateJSGeneratorObject(int pos, FunctionKind kind);
     542             : 
     543             :   // Generic AST generator for throwing errors from compiled code.
     544             :   Expression* NewThrowError(Runtime::FunctionId function_id,
     545             :                             MessageTemplate message, const AstRawString* arg,
     546             :                             int pos);
     547             : 
     548             :   Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion,
     549             :                                     IteratorType type, int pos);
     550             :   Statement* CheckCallable(Variable* var, Expression* error, int pos);
     551             : 
     552             :   void RewriteAsyncFunctionBody(ScopedPtrList<Statement>* body, Block* block,
     553             :                                 Expression* return_value);
     554             : 
     555             :   void AddArrowFunctionFormalParameters(ParserFormalParameters* parameters,
     556             :                                         Expression* params, int end_pos);
     557             :   void SetFunctionName(Expression* value, const AstRawString* name,
     558             :                        const AstRawString* prefix = nullptr);
     559             : 
     560             :   // Helper functions for recursive descent.
     561             :   V8_INLINE bool IsEval(const AstRawString* identifier) const {
     562    14454720 :     return identifier == ast_value_factory()->eval_string();
     563             :   }
     564             : 
     565             :   V8_INLINE bool IsAsync(const AstRawString* identifier) const {
     566             :     return identifier == ast_value_factory()->async_string();
     567             :   }
     568             : 
     569             :   V8_INLINE bool IsArguments(const AstRawString* identifier) const {
     570    42107085 :     return identifier == ast_value_factory()->arguments_string();
     571             :   }
     572             : 
     573             :   V8_INLINE bool IsLet(const AstRawString* identifier) const {
     574     2332541 :     return identifier == ast_value_factory()->let_string();
     575             :   }
     576             : 
     577             :   V8_INLINE bool IsEvalOrArguments(const AstRawString* identifier) const {
     578    18608596 :     return IsEval(identifier) || IsArguments(identifier);
     579             :   }
     580             : 
     581             :   // Returns true if the expression is of type "this.foo".
     582             :   V8_INLINE static bool IsThisProperty(Expression* expression) {
     583             :     DCHECK_NOT_NULL(expression);
     584     9508899 :     Property* property = expression->AsProperty();
     585    17365336 :     return property != nullptr && property->obj()->IsVariableProxy() &&
     586     7806238 :            property->obj()->AsVariableProxy()->is_this();
     587             :   }
     588             : 
     589             :   // This returns true if the expression is an indentifier (wrapped
     590             :   // inside a variable proxy).  We exclude the case of 'this', which
     591             :   // has been converted to a variable proxy.
     592             :   V8_INLINE static bool IsIdentifier(Expression* expression) {
     593   104742561 :     VariableProxy* operand = expression->AsVariableProxy();
     594   138670555 :     return operand != nullptr && !operand->is_this() &&
     595    33927793 :            !operand->is_new_target();
     596             :   }
     597             : 
     598             :   V8_INLINE static const AstRawString* AsIdentifier(Expression* expression) {
     599             :     DCHECK(IsIdentifier(expression));
     600    14049706 :     return expression->AsVariableProxy()->raw_name();
     601             :   }
     602             : 
     603             :   V8_INLINE VariableProxy* AsIdentifierExpression(Expression* expression) {
     604       15783 :     return expression->AsVariableProxy();
     605             :   }
     606             : 
     607             :   V8_INLINE bool IsConstructor(const AstRawString* identifier) const {
     608      336111 :     return identifier == ast_value_factory()->constructor_string();
     609             :   }
     610             : 
     611             :   V8_INLINE bool IsName(const AstRawString* identifier) const {
     612       62473 :     return identifier == ast_value_factory()->name_string();
     613             :   }
     614             : 
     615             :   V8_INLINE static bool IsBoilerplateProperty(
     616             :       ObjectLiteral::Property* property) {
     617     3038539 :     return !property->IsPrototype();
     618             :   }
     619             : 
     620             :   V8_INLINE bool IsNative(Expression* expr) const {
     621             :     DCHECK_NOT_NULL(expr);
     622        3532 :     return expr->IsVariableProxy() &&
     623        3532 :            expr->AsVariableProxy()->raw_name() ==
     624        1766 :                ast_value_factory()->native_string();
     625             :   }
     626             : 
     627             :   V8_INLINE static bool IsArrayIndex(const AstRawString* string,
     628             :                                      uint32_t* index) {
     629       56345 :     return string->AsArrayIndex(index);
     630             :   }
     631             : 
     632             :   // Returns true if the statement is an expression statement containing
     633             :   // a single string literal.  If a second argument is given, the literal
     634             :   // is also compared with it and the result is true only if they are equal.
     635             :   V8_INLINE bool IsStringLiteral(Statement* statement,
     636             :                                  const AstRawString* arg = nullptr) const {
     637     2628194 :     ExpressionStatement* e_stat = statement->AsExpressionStatement();
     638     1314096 :     if (e_stat == nullptr) return false;
     639     1314097 :     Literal* literal = e_stat->expression()->AsLiteral();
     640     1314096 :     if (literal == nullptr || !literal->IsString()) return false;
     641             :     return arg == nullptr || literal->AsRawString() == arg;
     642             :   }
     643             : 
     644             :   V8_INLINE void GetDefaultStrings(
     645             :       const AstRawString** default_string,
     646             :       const AstRawString** star_default_star_string) {
     647          65 :     *default_string = ast_value_factory()->default_string();
     648          65 :     *star_default_star_string = ast_value_factory()->star_default_star_string();
     649             :   }
     650             : 
     651             :   // Functions for encapsulating the differences between parsing and preparsing;
     652             :   // operations interleaved with the recursive descent.
     653             :   V8_INLINE void PushLiteralName(const AstRawString* id) {
     654     9076705 :     fni_.PushLiteralName(id);
     655             :   }
     656             : 
     657             :   V8_INLINE void PushVariableName(const AstRawString* id) {
     658             :     fni_.PushVariableName(id);
     659             :   }
     660             : 
     661             :   V8_INLINE void PushPropertyName(Expression* expression) {
     662     1783652 :     if (expression->IsPropertyName()) {
     663       41482 :       fni_.PushLiteralName(expression->AsLiteral()->AsRawPropertyName());
     664             :     } else {
     665     1762894 :       fni_.PushLiteralName(ast_value_factory()->anonymous_function_string());
     666             :     }
     667             :   }
     668             : 
     669             :   V8_INLINE void PushEnclosingName(const AstRawString* name) {
     670      926022 :     fni_.PushEnclosingName(name);
     671             :   }
     672             : 
     673             :   V8_INLINE void AddFunctionForNameInference(FunctionLiteral* func_to_infer) {
     674      672943 :     fni_.AddFunction(func_to_infer);
     675             :   }
     676             : 
     677      393837 :   V8_INLINE void InferFunctionName() { fni_.Infer(); }
     678             : 
     679             :   // If we assign a function literal to a property we pretenure the
     680             :   // literal so it can be added as a constant function property.
     681             :   V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
     682             :       Expression* left, Expression* right) {
     683             :     DCHECK_NOT_NULL(left);
     684     9508887 :     if (left->IsProperty() && right->IsFunctionLiteral()) {
     685      167480 :       right->AsFunctionLiteral()->set_pretenure();
     686             :     }
     687             :   }
     688             : 
     689             :   // A shortcut for performing a ToString operation
     690             :   V8_INLINE Expression* ToString(Expression* expr) {
     691             :     if (expr->IsStringLiteral()) return expr;
     692             :     ScopedPtrList<Expression> args(pointer_buffer());
     693             :     args.Add(expr);
     694             :     return factory()->NewCallRuntime(Runtime::kInlineToString, args,
     695             :                                      expr->position());
     696             :   }
     697             : 
     698             :   // Returns true if we have a binary expression between two numeric
     699             :   // literals. In that case, *x will be changed to an expression which is the
     700             :   // computed value.
     701             :   bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
     702             :                                               Token::Value op, int pos);
     703             : 
     704             :   // Returns true if we have a binary operation between a binary/n-ary
     705             :   // expression (with the same operation) and a value, which can be collapsed
     706             :   // into a single n-ary expression. In that case, *x will be changed to an
     707             :   // n-ary expression.
     708             :   bool CollapseNaryExpression(Expression** x, Expression* y, Token::Value op,
     709             :                               int pos, const SourceRange& range);
     710             : 
     711             :   // Returns a UnaryExpression or, in one of the following cases, a Literal.
     712             :   // ! <literal> -> true / false
     713             :   // + <Number literal> -> <Number literal>
     714             :   // - <Number literal> -> <Number literal with value negated>
     715             :   // ~ <literal> -> true / false
     716             :   Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
     717             :                                    int pos);
     718             : 
     719             :   // Generate AST node that throws a ReferenceError with the given type.
     720             :   V8_INLINE Expression* NewThrowReferenceError(MessageTemplate message,
     721             :                                                int pos) {
     722             :     return NewThrowError(Runtime::kNewReferenceError, message,
     723        1219 :                          ast_value_factory()->empty_string(), pos);
     724             :   }
     725             : 
     726             :   // Generate AST node that throws a SyntaxError with the given
     727             :   // type. The first argument may be null (in the handle sense) in
     728             :   // which case no arguments are passed to the constructor.
     729             :   V8_INLINE Expression* NewThrowSyntaxError(MessageTemplate message,
     730             :                                             const AstRawString* arg, int pos) {
     731             :     return NewThrowError(Runtime::kNewSyntaxError, message, arg, pos);
     732             :   }
     733             : 
     734             :   // Generate AST node that throws a TypeError with the given
     735             :   // type. Both arguments must be non-null (in the handle sense).
     736             :   V8_INLINE Expression* NewThrowTypeError(MessageTemplate message,
     737             :                                           const AstRawString* arg, int pos) {
     738           0 :     return NewThrowError(Runtime::kNewTypeError, message, arg, pos);
     739             :   }
     740             : 
     741             :   // Reporting errors.
     742     1924372 :   void ReportMessageAt(Scanner::Location source_location,
     743             :                        MessageTemplate message, const char* arg = nullptr,
     744             :                        ParseErrorType error_type = kSyntaxError) {
     745     1924372 :     if (stack_overflow()) {
     746             :       // Suppress the error message (syntax error or such) in the presence of a
     747             :       // stack overflow. The isolate allows only one pending exception at at
     748             :       // time
     749             :       // and we want to report the stack overflow later.
     750     1924372 :       return;
     751             :     }
     752             :     pending_error_handler()->ReportMessageAt(source_location.beg_pos,
     753             :                                              source_location.end_pos, message,
     754     1880035 :                                              arg, error_type);
     755             :     scanner_.set_parser_error();
     756             :   }
     757             : 
     758             :   // Dummy implementation. The parser should never have a unidentifiable
     759             :   // error.
     760             :   V8_INLINE void ReportUnidentifiableError() { UNREACHABLE(); }
     761             : 
     762       78152 :   void ReportMessageAt(Scanner::Location source_location,
     763             :                        MessageTemplate message, const AstRawString* arg,
     764             :                        ParseErrorType error_type = kSyntaxError) {
     765       78152 :     if (stack_overflow()) {
     766             :       // Suppress the error message (syntax error or such) in the presence of a
     767             :       // stack overflow. The isolate allows only one pending exception at at
     768             :       // time
     769             :       // and we want to report the stack overflow later.
     770       78152 :       return;
     771             :     }
     772             :     pending_error_handler()->ReportMessageAt(source_location.beg_pos,
     773             :                                              source_location.end_pos, message,
     774       78152 :                                              arg, error_type);
     775             :     scanner_.set_parser_error();
     776             :   }
     777             : 
     778             :   // "null" return type creators.
     779             :   V8_INLINE static std::nullptr_t NullIdentifier() { return nullptr; }
     780             :   V8_INLINE static std::nullptr_t NullExpression() { return nullptr; }
     781             :   V8_INLINE static std::nullptr_t NullLiteralProperty() { return nullptr; }
     782             :   V8_INLINE static ZonePtrList<Expression>* NullExpressionList() {
     783             :     return nullptr;
     784             :   }
     785             :   V8_INLINE static ZonePtrList<Statement>* NullStatementList() {
     786             :     return nullptr;
     787             :   }
     788             :   V8_INLINE static std::nullptr_t NullStatement() { return nullptr; }
     789             :   V8_INLINE static std::nullptr_t NullBlock() { return nullptr; }
     790      679193 :   Expression* FailureExpression() { return factory()->FailureExpression(); }
     791             : 
     792             :   template <typename T>
     793             :   V8_INLINE static bool IsNull(T subject) {
     794      182194 :     return subject == nullptr;
     795             :   }
     796             : 
     797             :   // Non-null empty string.
     798             :   V8_INLINE const AstRawString* EmptyIdentifierString() const {
     799      658921 :     return ast_value_factory()->empty_string();
     800             :   }
     801             : 
     802             :   // Producing data during the recursive descent.
     803             :   V8_INLINE const AstRawString* GetSymbol() const {
     804    48428213 :     const AstRawString* result = scanner()->CurrentSymbol(ast_value_factory());
     805             :     DCHECK_NOT_NULL(result);
     806             :     return result;
     807             :   }
     808             : 
     809             :   V8_INLINE const AstRawString* GetNextSymbol() const {
     810       49265 :     return scanner()->NextSymbol(ast_value_factory());
     811             :   }
     812             : 
     813             :   V8_INLINE const AstRawString* GetNumberAsSymbol() const {
     814        3698 :     double double_value = scanner()->DoubleValue();
     815             :     char array[100];
     816        3698 :     const char* string = DoubleToCString(double_value, ArrayVector(array));
     817        3698 :     return ast_value_factory()->GetOneByteString(string);
     818             :   }
     819             : 
     820             :   V8_INLINE Expression* ThisExpression(int pos = kNoSourcePosition) {
     821             :     return NewUnresolved(ast_value_factory()->this_string(), pos,
     822     2524096 :                          THIS_VARIABLE);
     823             :   }
     824             : 
     825             :   Expression* NewSuperPropertyReference(int pos);
     826             :   Expression* NewSuperCallReference(int pos);
     827             :   Expression* NewTargetExpression(int pos);
     828             :   Expression* ImportMetaExpression(int pos);
     829             : 
     830             :   Expression* ExpressionFromLiteral(Token::Value token, int pos);
     831             : 
     832             :   V8_INLINE VariableProxy* ExpressionFromIdentifier(
     833             :       const AstRawString* name, int start_position,
     834             :       InferName infer = InferName::kYes) {
     835             :     if (infer == InferName::kYes) {
     836    32833490 :       fni_.PushVariableName(name);
     837             :     }
     838    32895717 :     return expression_scope()->NewVariable(name, start_position);
     839             :   }
     840             : 
     841             :   V8_INLINE Variable* DeclareCatchVariableName(Scope* scope,
     842             :                                                const AstRawString* name) {
     843       86228 :     return scope->DeclareCatchVariableName(name);
     844             :   }
     845             : 
     846             :   V8_INLINE ZonePtrList<Expression>* NewExpressionList(int size) const {
     847             :     return new (zone()) ZonePtrList<Expression>(size, zone());
     848             :   }
     849             :   V8_INLINE ZonePtrList<ObjectLiteral::Property>* NewObjectPropertyList(
     850             :       int size) const {
     851             :     return new (zone()) ZonePtrList<ObjectLiteral::Property>(size, zone());
     852             :   }
     853             :   V8_INLINE ZonePtrList<ClassLiteral::Property>* NewClassPropertyList(
     854             :       int size) const {
     855      544499 :     return new (zone()) ZonePtrList<ClassLiteral::Property>(size, zone());
     856             :   }
     857             :   V8_INLINE ZonePtrList<Statement>* NewStatementList(int size) const {
     858             :     return new (zone()) ZonePtrList<Statement>(size, zone());
     859             :   }
     860             : 
     861             :   Expression* NewV8Intrinsic(const AstRawString* name,
     862             :                              const ScopedPtrList<Expression>& args, int pos);
     863             : 
     864             :   V8_INLINE Statement* NewThrowStatement(Expression* exception, int pos) {
     865             :     return factory()->NewExpressionStatement(
     866       40752 :         factory()->NewThrow(exception, pos), pos);
     867             :   }
     868             : 
     869             :   V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
     870             :                                     Expression* pattern,
     871             :                                     Expression* initializer,
     872             :                                     int initializer_end_position,
     873             :                                     bool is_rest) {
     874     4022965 :     parameters->UpdateArityAndFunctionLength(initializer != nullptr, is_rest);
     875     4022965 :     auto parameter = new (parameters->scope->zone())
     876             :         ParserFormalParameters::Parameter(pattern, initializer,
     877     4022965 :                                           scanner()->location().beg_pos,
     878     8045930 :                                           initializer_end_position, is_rest);
     879             : 
     880     4022952 :     parameters->params.Add(parameter);
     881             :   }
     882             : 
     883             :   V8_INLINE void DeclareFormalParameters(ParserFormalParameters* parameters) {
     884     1569452 :     bool is_simple = parameters->is_simple;
     885     1569452 :     DeclarationScope* scope = parameters->scope;
     886     1569452 :     if (!is_simple) scope->SetHasNonSimpleParameters();
     887     9931462 :     for (auto parameter : parameters->params) {
     888     2840701 :       bool is_optional = parameter->initializer() != nullptr;
     889             :       // If the parameter list is simple, declare the parameters normally with
     890             :       // their names. If the parameter list is not simple, declare a temporary
     891             :       // for each parameter - the corresponding named variable is declared by
     892             :       // BuildParamerterInitializationBlock.
     893     5598050 :       if (is_simple && !parameters->has_duplicate() &&
     894     2757346 :           scope->LookupLocal(parameter->name())) {
     895             :         parameters->duplicate_loc = Scanner::Location(
     896             :             parameter->position,
     897        3730 :             parameter->position + parameter->name()->length());
     898             :       }
     899             :       scope->DeclareParameter(
     900       78615 :           is_simple ? parameter->name() : ast_value_factory()->empty_string(),
     901             :           is_simple ? VariableMode::kVar : VariableMode::kTemporary,
     902     2840711 :           is_optional, parameter->is_rest(), ast_value_factory(),
     903     8522118 :           parameter->position);
     904             :     }
     905             :   }
     906             : 
     907             :   void DeclareArrowFunctionFormalParameters(
     908             :       ParserFormalParameters* parameters, Expression* params,
     909             :       const Scanner::Location& params_loc);
     910             : 
     911             :   Expression* ExpressionListToExpression(const ScopedPtrList<Expression>& args);
     912             : 
     913             :   void SetFunctionNameFromPropertyName(LiteralProperty* property,
     914             :                                        const AstRawString* name,
     915             :                                        const AstRawString* prefix = nullptr);
     916             :   void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
     917             :                                        const AstRawString* name,
     918             :                                        const AstRawString* prefix = nullptr);
     919             : 
     920             :   void SetFunctionNameFromIdentifierRef(Expression* value,
     921             :                                         Expression* identifier);
     922             : 
     923             :   V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) {
     924        1219 :     ++use_counts_[feature];
     925             :   }
     926             : 
     927             :   // Returns true iff we're parsing the first function literal during
     928             :   // CreateDynamicFunction().
     929             :   V8_INLINE bool ParsingDynamicFunctionDeclaration() const {
     930             :     return parameters_end_pos_ != kNoSourcePosition;
     931             :   }
     932             : 
     933             :   V8_INLINE void ConvertBinaryToNaryOperationSourceRange(
     934             :       BinaryOperation* binary_op, NaryOperation* nary_op) {
     935      234816 :     if (source_range_map_ == nullptr) return;
     936             :     DCHECK_NULL(source_range_map_->Find(nary_op));
     937             : 
     938             :     BinaryOperationSourceRanges* ranges =
     939             :         static_cast<BinaryOperationSourceRanges*>(
     940         130 :             source_range_map_->Find(binary_op));
     941         130 :     if (ranges == nullptr) return;
     942             : 
     943         130 :     SourceRange range = ranges->GetRange(SourceRangeKind::kRight);
     944             :     source_range_map_->Insert(
     945         130 :         nary_op, new (zone()) NaryOperationSourceRanges(zone(), range));
     946             :   }
     947             : 
     948             :   V8_INLINE void AppendNaryOperationSourceRange(NaryOperation* node,
     949             :                                                 const SourceRange& range) {
     950      317759 :     if (source_range_map_ == nullptr) return;
     951             :     NaryOperationSourceRanges* ranges =
     952         175 :         static_cast<NaryOperationSourceRanges*>(source_range_map_->Find(node));
     953         175 :     if (ranges == nullptr) return;
     954             : 
     955         175 :     ranges->AddRange(range);
     956             :     DCHECK_EQ(node->subsequent_length(), ranges->RangeCount());
     957             :   }
     958             : 
     959             :   V8_INLINE void RecordBlockSourceRange(Block* node,
     960             :                                         int32_t continuation_position) {
     961      944635 :     if (source_range_map_ == nullptr) return;
     962             :     source_range_map_->Insert(
     963         725 :         node, new (zone()) BlockSourceRanges(continuation_position));
     964             :   }
     965             : 
     966             :   V8_INLINE void RecordCaseClauseSourceRange(CaseClause* node,
     967             :                                              const SourceRange& body_range) {
     968       88679 :     if (source_range_map_ == nullptr) return;
     969             :     source_range_map_->Insert(node,
     970          30 :                               new (zone()) CaseClauseSourceRanges(body_range));
     971             :   }
     972             : 
     973             :   V8_INLINE void RecordConditionalSourceRange(Expression* node,
     974             :                                               const SourceRange& then_range,
     975             :                                               const SourceRange& else_range) {
     976       48516 :     if (source_range_map_ == nullptr) return;
     977             :     source_range_map_->Insert(
     978             :         node->AsConditional(),
     979         200 :         new (zone()) ConditionalSourceRanges(then_range, else_range));
     980             :   }
     981             : 
     982             :   V8_INLINE void RecordBinaryOperationSourceRange(
     983             :       Expression* node, const SourceRange& right_range) {
     984      140369 :     if (source_range_map_ == nullptr) return;
     985             :     source_range_map_->Insert(node->AsBinaryOperation(),
     986             :                               new (zone())
     987         580 :                                   BinaryOperationSourceRanges(right_range));
     988             :   }
     989             : 
     990             :   V8_INLINE void RecordJumpStatementSourceRange(Statement* node,
     991             :                                                 int32_t continuation_position) {
     992     1024938 :     if (source_range_map_ == nullptr) return;
     993             :     source_range_map_->Insert(
     994             :         static_cast<JumpStatement*>(node),
     995         720 :         new (zone()) JumpStatementSourceRanges(continuation_position));
     996             :   }
     997             : 
     998             :   V8_INLINE void RecordIfStatementSourceRange(Statement* node,
     999             :                                               const SourceRange& then_range,
    1000             :                                               const SourceRange& else_range) {
    1001      610828 :     if (source_range_map_ == nullptr) return;
    1002             :     source_range_map_->Insert(
    1003             :         node->AsIfStatement(),
    1004        1140 :         new (zone()) IfStatementSourceRanges(then_range, else_range));
    1005             :   }
    1006             : 
    1007             :   V8_INLINE void RecordIterationStatementSourceRange(
    1008             :       IterationStatement* node, const SourceRange& body_range) {
    1009      489419 :     if (source_range_map_ == nullptr) return;
    1010             :     source_range_map_->Insert(
    1011         305 :         node, new (zone()) IterationStatementSourceRanges(body_range));
    1012             :   }
    1013             : 
    1014             :   V8_INLINE void RecordSuspendSourceRange(Expression* node,
    1015             :                                           int32_t continuation_position) {
    1016       47033 :     if (source_range_map_ == nullptr) return;
    1017             :     source_range_map_->Insert(static_cast<Suspend*>(node),
    1018             :                               new (zone())
    1019         145 :                                   SuspendSourceRanges(continuation_position));
    1020             :   }
    1021             : 
    1022             :   V8_INLINE void RecordSwitchStatementSourceRange(
    1023             :       Statement* node, int32_t continuation_position) {
    1024       13538 :     if (source_range_map_ == nullptr) return;
    1025             :     source_range_map_->Insert(
    1026             :         node->AsSwitchStatement(),
    1027          30 :         new (zone()) SwitchStatementSourceRanges(continuation_position));
    1028             :   }
    1029             : 
    1030             :   V8_INLINE void RecordThrowSourceRange(Statement* node,
    1031             :                                         int32_t continuation_position) {
    1032       40755 :     if (source_range_map_ == nullptr) return;
    1033          35 :     ExpressionStatement* expr_stmt = static_cast<ExpressionStatement*>(node);
    1034          35 :     Throw* throw_expr = expr_stmt->expression()->AsThrow();
    1035             :     source_range_map_->Insert(
    1036          35 :         throw_expr, new (zone()) ThrowSourceRanges(continuation_position));
    1037             :   }
    1038             : 
    1039             :   V8_INLINE void RecordTryCatchStatementSourceRange(
    1040             :       TryCatchStatement* node, const SourceRange& body_range) {
    1041       88910 :     if (source_range_map_ == nullptr) return;
    1042             :     source_range_map_->Insert(
    1043          65 :         node, new (zone()) TryCatchStatementSourceRanges(body_range));
    1044             :   }
    1045             : 
    1046             :   V8_INLINE void RecordTryFinallyStatementSourceRange(
    1047             :       TryFinallyStatement* node, const SourceRange& body_range) {
    1048        5190 :     if (source_range_map_ == nullptr) return;
    1049             :     source_range_map_->Insert(
    1050          35 :         node, new (zone()) TryFinallyStatementSourceRanges(body_range));
    1051             :   }
    1052             : 
    1053             :   // Generate the next internal variable name for binding an exported namespace
    1054             :   // object (used to implement the "export * as" syntax).
    1055             :   const AstRawString* NextInternalNamespaceExportName();
    1056             : 
    1057             :   ParseInfo* info() const { return info_; }
    1058             : 
    1059             :   std::vector<uint8_t>* preparse_data_buffer() {
    1060             :     return &preparse_data_buffer_;
    1061             :   }
    1062             : 
    1063             :   // Parser's private field members.
    1064             :   friend class PreParserZoneScope;  // Uses reusable_preparser().
    1065             :   friend class PreparseDataBuilder;  // Uses preparse_data_buffer()
    1066             : 
    1067             :   ParseInfo* info_;
    1068             :   Scanner scanner_;
    1069             :   Zone preparser_zone_;
    1070             :   PreParser* reusable_preparser_;
    1071             :   Mode mode_;
    1072             : 
    1073             :   SourceRangeMap* source_range_map_ = nullptr;
    1074             : 
    1075             :   friend class ParserTarget;
    1076             :   friend class ParserTargetScope;
    1077             :   ParserTarget* target_stack_;  // for break, continue statements
    1078             : 
    1079             :   ScriptCompiler::CompileOptions compile_options_;
    1080             : 
    1081             :   // For NextInternalNamespaceExportName().
    1082             :   int number_of_named_namespace_exports_ = 0;
    1083             : 
    1084             :   // Other information which will be stored in Parser and moved to Isolate after
    1085             :   // parsing.
    1086             :   int use_counts_[v8::Isolate::kUseCounterFeatureCount];
    1087             :   int total_preparse_skipped_;
    1088             :   bool allow_lazy_;
    1089             :   bool temp_zoned_;
    1090             :   ConsumedPreparseData* consumed_preparse_data_;
    1091             :   std::vector<uint8_t> preparse_data_buffer_;
    1092             : 
    1093             :   // If not kNoSourcePosition, indicates that the first function literal
    1094             :   // encountered is a dynamic function, see CreateDynamicFunction(). This field
    1095             :   // indicates the correct position of the ')' that closes the parameter list.
    1096             :   // After that ')' is encountered, this field is reset to kNoSourcePosition.
    1097             :   int parameters_end_pos_;
    1098             : };
    1099             : 
    1100             : // ----------------------------------------------------------------------------
    1101             : // Target is a support class to facilitate manipulation of the
    1102             : // Parser's target_stack_ (the stack of potential 'break' and
    1103             : // 'continue' statement targets). Upon construction, a new target is
    1104             : // added; it is removed upon destruction.
    1105             : 
    1106             : class ParserTarget {
    1107             :  public:
    1108             :   ParserTarget(ParserBase<Parser>* parser, BreakableStatement* statement)
    1109             :       : variable_(&parser->impl()->target_stack_),
    1110             :         statement_(statement),
    1111     1482726 :         previous_(parser->impl()->target_stack_) {
    1112     1482726 :     parser->impl()->target_stack_ = this;
    1113             :   }
    1114             : 
    1115     1482741 :   ~ParserTarget() { *variable_ = previous_; }
    1116             : 
    1117             :   ParserTarget* previous() { return previous_; }
    1118             :   BreakableStatement* statement() { return statement_; }
    1119             : 
    1120             :  private:
    1121             :   ParserTarget** variable_;
    1122             :   BreakableStatement* statement_;
    1123             :   ParserTarget* previous_;
    1124             : };
    1125             : 
    1126             : class ParserTargetScope {
    1127             :  public:
    1128     3046647 :   explicit ParserTargetScope(ParserBase<Parser>* parser)
    1129             :       : variable_(&parser->impl()->target_stack_),
    1130     3046647 :         previous_(parser->impl()->target_stack_) {
    1131     3046647 :     parser->impl()->target_stack_ = nullptr;
    1132     3046647 :   }
    1133             : 
    1134     3046626 :   ~ParserTargetScope() { *variable_ = previous_; }
    1135             : 
    1136             :  private:
    1137             :   ParserTarget** variable_;
    1138             :   ParserTarget* previous_;
    1139             : };
    1140             : 
    1141             : }  // namespace internal
    1142             : }  // namespace v8
    1143             : 
    1144             : #endif  // V8_PARSING_PARSER_H_

Generated by: LCOV version 1.10