LCOV - code coverage report
Current view: top level - src/parsing - parse-info.h (source / functions) Hit Total Coverage
Test: app.info Lines: 53 53 100.0 %
Date: 2019-02-19 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2016 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_PARSE_INFO_H_
       6             : #define V8_PARSING_PARSE_INFO_H_
       7             : 
       8             : #include <map>
       9             : #include <memory>
      10             : #include <vector>
      11             : 
      12             : #include "include/v8.h"
      13             : #include "src/function-kind.h"
      14             : #include "src/globals.h"
      15             : #include "src/handles.h"
      16             : #include "src/objects/script.h"
      17             : #include "src/parsing/preparse-data.h"
      18             : #include "src/pending-compilation-error-handler.h"
      19             : 
      20             : namespace v8 {
      21             : 
      22             : class Extension;
      23             : 
      24             : namespace internal {
      25             : 
      26             : class AccountingAllocator;
      27             : class AstRawString;
      28             : class AstStringConstants;
      29             : class AstValueFactory;
      30             : class CompilerDispatcher;
      31             : class DeclarationScope;
      32             : class FunctionLiteral;
      33             : class RuntimeCallStats;
      34             : class Logger;
      35             : class SourceRangeMap;
      36             : class Utf16CharacterStream;
      37             : class Zone;
      38             : 
      39             : // A container for the inputs, configuration options, and outputs of parsing.
      40     4875404 : class V8_EXPORT_PRIVATE ParseInfo {
      41             :  public:
      42             :   explicit ParseInfo(AccountingAllocator* zone_allocator);
      43             :   explicit ParseInfo(Isolate*);
      44             :   ParseInfo(Isolate*, AccountingAllocator* zone_allocator);
      45             :   ParseInfo(Isolate* isolate, Handle<Script> script);
      46             :   ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared);
      47             : 
      48             :   // Creates a new parse info based on parent top-level |outer_parse_info| for
      49             :   // function |literal|.
      50             :   static std::unique_ptr<ParseInfo> FromParent(
      51             :       const ParseInfo* outer_parse_info, AccountingAllocator* zone_allocator,
      52             :       const FunctionLiteral* literal, const AstRawString* function_name);
      53             : 
      54             :   ~ParseInfo();
      55             : 
      56             :   Handle<Script> CreateScript(Isolate* isolate, Handle<String> source,
      57             :                               ScriptOriginOptions origin_options,
      58             :                               NativesFlag natives = NOT_NATIVES_CODE);
      59             : 
      60             :   // Either returns the ast-value-factory associcated with this ParseInfo, or
      61             :   // creates and returns a new factory if none exists.
      62             :   AstValueFactory* GetOrCreateAstValueFactory();
      63             : 
      64             :   Zone* zone() const { return zone_.get(); }
      65             : 
      66             : // Convenience accessor methods for flags.
      67             : #define FLAG_ACCESSOR(flag, getter, setter)     \
      68             :   bool getter() const { return GetFlag(flag); } \
      69             :   void setter() { SetFlag(flag); }              \
      70             :   void setter(bool val) { SetFlag(flag, val); }
      71             : 
      72     2817391 :   FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel)
      73             :   FLAG_ACCESSOR(kEager, is_eager, set_eager)
      74    11098245 :   FLAG_ACCESSOR(kEval, is_eval, set_eval)
      75      723286 :   FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode)
      76     2090832 :   FLAG_ACCESSOR(kNative, is_native, set_native)
      77     4875247 :   FLAG_ACCESSOR(kModule, is_module, set_module)
      78             :   FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
      79             :   FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
      80             :                 set_is_named_expression)
      81             :   FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile)
      82     2090832 :   FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile,
      83             :                 set_collect_type_profile)
      84     2089575 :   FLAG_ACCESSOR(kIsAsmWasmBroken, is_asm_wasm_broken, set_asm_wasm_broken)
      85     2437454 :   FLAG_ACCESSOR(kContainsAsmModule, contains_asm_module,
      86             :                 set_contains_asm_module)
      87      979118 :   FLAG_ACCESSOR(kCoverageEnabled, coverage_enabled, set_coverage_enabled)
      88       13104 :   FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled,
      89             :                 set_block_coverage_enabled)
      90     7243183 :   FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread,
      91             :                 set_on_background_thread)
      92     2916396 :   FLAG_ACCESSOR(kWrappedAsFunction, is_wrapped_as_function,
      93             :                 set_wrapped_as_function)
      94      846117 :   FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache)
      95             :   FLAG_ACCESSOR(kIsDeclaration, is_declaration, set_declaration)
      96      701310 :   FLAG_ACCESSOR(kRequiresInstanceMembersInitializer,
      97             :                 requires_instance_members_initializer,
      98             :                 set_requires_instance_members_initializer)
      99     2090832 :   FLAG_ACCESSOR(kMightAlwaysOpt, might_always_opt, set_might_always_opt)
     100     2437590 :   FLAG_ACCESSOR(kAllowNativeSyntax, allow_natives_syntax,
     101             :                 set_allow_natives_syntax)
     102     4875180 :   FLAG_ACCESSOR(kAllowLazyCompile, allow_lazy_compile, set_allow_lazy_compile)
     103             :   FLAG_ACCESSOR(kAllowNativeSyntax, allow_native_syntax,
     104             :                 set_allow_native_syntax)
     105     2437590 :   FLAG_ACCESSOR(kAllowHarmonyPublicFields, allow_harmony_public_fields,
     106             :                 set_allow_harmony_public_fields)
     107     2437590 :   FLAG_ACCESSOR(kAllowHarmonyStaticFields, allow_harmony_static_fields,
     108             :                 set_allow_harmony_static_fields)
     109     2437590 :   FLAG_ACCESSOR(kAllowHarmonyDynamicImport, allow_harmony_dynamic_import,
     110             :                 set_allow_harmony_dynamic_import)
     111     2437590 :   FLAG_ACCESSOR(kAllowHarmonyImportMeta, allow_harmony_import_meta,
     112             :                 set_allow_harmony_import_meta)
     113     2437590 :   FLAG_ACCESSOR(kAllowHarmonyNumericSeparator, allow_harmony_numeric_separator,
     114             :                 set_allow_harmony_numeric_separator)
     115     2437590 :   FLAG_ACCESSOR(kAllowHarmonyPrivateFields, allow_harmony_private_fields,
     116             :                 set_allow_harmony_private_fields)
     117     2437590 :   FLAG_ACCESSOR(kAllowHarmonyPrivateMethods, allow_harmony_private_methods,
     118             :                 set_allow_harmony_private_methods)
     119      701310 :   FLAG_ACCESSOR(kIsOneshotIIFE, is_oneshot_iife, set_is_oneshot_iife)
     120     2090832 :   FLAG_ACCESSOR(kCollectSourcePositions, collect_source_positions,
     121             :                 set_collect_source_positions)
     122             : #undef FLAG_ACCESSOR
     123             : 
     124             :   void set_parse_restriction(ParseRestriction restriction) {
     125             :     SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
     126             :   }
     127             : 
     128     1731032 :   ParseRestriction parse_restriction() const {
     129             :     return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
     130     1731032 :                                       : NO_PARSE_RESTRICTION;
     131             :   }
     132             : 
     133             :   Utf16CharacterStream* character_stream() const {
     134             :     return character_stream_.get();
     135             :   }
     136             :   void set_character_stream(
     137             :       std::unique_ptr<Utf16CharacterStream> character_stream);
     138             :   void ResetCharacterStream();
     139             : 
     140             :   v8::Extension* extension() const { return extension_; }
     141      154967 :   void set_extension(v8::Extension* extension) { extension_ = extension; }
     142             : 
     143             :   void set_consumed_preparse_data(std::unique_ptr<ConsumedPreparseData> data) {
     144             :     consumed_preparse_data_.swap(data);
     145             :   }
     146             :   ConsumedPreparseData* consumed_preparse_data() {
     147             :     return consumed_preparse_data_.get();
     148             :   }
     149             : 
     150             :   DeclarationScope* script_scope() const { return script_scope_; }
     151             :   void set_script_scope(DeclarationScope* script_scope) {
     152     2437632 :     script_scope_ = script_scope;
     153             :   }
     154             : 
     155         222 :   AstValueFactory* ast_value_factory() const {
     156             :     DCHECK(ast_value_factory_.get());
     157         222 :     return ast_value_factory_.get();
     158             :   }
     159             : 
     160             :   const AstRawString* function_name() const { return function_name_; }
     161             :   void set_function_name(const AstRawString* function_name) {
     162      706533 :     function_name_ = function_name;
     163             :   }
     164             : 
     165         222 :   FunctionLiteral* literal() const { return literal_; }
     166     2437625 :   void set_literal(FunctionLiteral* literal) { literal_ = literal; }
     167             : 
     168             :   DeclarationScope* scope() const;
     169             : 
     170             :   uintptr_t stack_limit() const { return stack_limit_; }
     171     2463984 :   void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
     172             : 
     173             :   uint64_t hash_seed() const { return hash_seed_; }
     174     2437706 :   void set_hash_seed(uint64_t hash_seed) { hash_seed_ = hash_seed; }
     175             : 
     176             :   int start_position() const { return start_position_; }
     177             :   void set_start_position(int start_position) {
     178      708469 :     start_position_ = start_position;
     179             :   }
     180             : 
     181             :   int end_position() const { return end_position_; }
     182      708471 :   void set_end_position(int end_position) { end_position_ = end_position; }
     183             : 
     184             :   int parameters_end_pos() const { return parameters_end_pos_; }
     185             :   void set_parameters_end_pos(int parameters_end_pos) {
     186      953204 :     parameters_end_pos_ = parameters_end_pos;
     187             :   }
     188             : 
     189             :   int function_literal_id() const { return function_literal_id_; }
     190             :   void set_function_literal_id(int function_literal_id) {
     191          80 :     function_literal_id_ = function_literal_id;
     192             :   }
     193             : 
     194             :   FunctionKind function_kind() const { return function_kind_; }
     195             :   void set_function_kind(FunctionKind function_kind) {
     196      708470 :     function_kind_ = function_kind;
     197             :   }
     198             : 
     199             :   int max_function_literal_id() const { return max_function_literal_id_; }
     200             :   void set_max_function_literal_id(int max_function_literal_id) {
     201     1731060 :     max_function_literal_id_ = max_function_literal_id;
     202             :   }
     203             : 
     204             :   const AstStringConstants* ast_string_constants() const {
     205             :     return ast_string_constants_;
     206             :   }
     207             :   void set_ast_string_constants(
     208             :       const AstStringConstants* ast_string_constants) {
     209     2437706 :     ast_string_constants_ = ast_string_constants;
     210             :   }
     211             : 
     212             :   RuntimeCallStats* runtime_call_stats() const { return runtime_call_stats_; }
     213             :   void set_runtime_call_stats(RuntimeCallStats* runtime_call_stats) {
     214     2463983 :     runtime_call_stats_ = runtime_call_stats;
     215             :   }
     216             :   Logger* logger() const { return logger_; }
     217     2437706 :   void set_logger(Logger* logger) { logger_ = logger; }
     218             : 
     219             :   void AllocateSourceRangeMap();
     220             :   SourceRangeMap* source_range_map() const { return source_range_map_; }
     221             :   void set_source_range_map(SourceRangeMap* source_range_map) {
     222         668 :     source_range_map_ = source_range_map;
     223             :   }
     224             : 
     225             :   PendingCompilationErrorHandler* pending_error_handler() {
     226             :     return &pending_error_handler_;
     227             :   }
     228             : 
     229             :   class ParallelTasks {
     230             :    public:
     231             :     explicit ParallelTasks(CompilerDispatcher* compiler_dispatcher)
     232          98 :         : dispatcher_(compiler_dispatcher) {
     233             :       DCHECK(dispatcher_);
     234             :     }
     235             : 
     236             :     void Enqueue(ParseInfo* outer_parse_info, const AstRawString* function_name,
     237             :                  FunctionLiteral* literal);
     238             : 
     239             :     typedef std::forward_list<std::pair<FunctionLiteral*, uintptr_t>>::iterator
     240             :         EnqueuedJobsIterator;
     241             : 
     242             :     EnqueuedJobsIterator begin() { return enqueued_jobs_.begin(); }
     243             :     EnqueuedJobsIterator end() { return enqueued_jobs_.end(); }
     244             : 
     245             :     CompilerDispatcher* dispatcher() { return dispatcher_; }
     246             : 
     247             :    private:
     248             :     CompilerDispatcher* dispatcher_;
     249             :     std::forward_list<std::pair<FunctionLiteral*, uintptr_t>> enqueued_jobs_;
     250             :   };
     251             : 
     252             :   ParallelTasks* parallel_tasks() { return parallel_tasks_.get(); }
     253             : 
     254             :   //--------------------------------------------------------------------------
     255             :   // TODO(titzer): these should not be part of ParseInfo.
     256             :   //--------------------------------------------------------------------------
     257             :   Handle<Script> script() const { return script_; }
     258             :   void set_script(Handle<Script> script);
     259             : 
     260             :   MaybeHandle<ScopeInfo> maybe_outer_scope_info() const {
     261             :     return maybe_outer_scope_info_;
     262             :   }
     263             :   void set_outer_scope_info(Handle<ScopeInfo> outer_scope_info) {
     264     1005052 :     maybe_outer_scope_info_ = outer_scope_info;
     265             :   }
     266             : 
     267             :   int script_id() const { return script_id_; }
     268             :   //--------------------------------------------------------------------------
     269             : 
     270             :   LanguageMode language_mode() const {
     271             :     return construct_language_mode(is_strict_mode());
     272             :   }
     273             :   void set_language_mode(LanguageMode language_mode) {
     274             :     STATIC_ASSERT(LanguageModeSize == 2);
     275             :     set_strict_mode(is_strict(language_mode));
     276             :   }
     277             : 
     278             :  private:
     279             :   void SetScriptForToplevelCompile(Isolate* isolate, Handle<Script> script);
     280             : 
     281             :   // Set function info flags based on those in either FunctionLiteral or
     282             :   // SharedFunctionInfo |function|
     283             :   template <typename T>
     284             :   void SetFunctionInfo(T function);
     285             : 
     286             :   // Various configuration flags for parsing.
     287             :   enum Flag {
     288             :     // ---------- Input flags ---------------------------
     289             :     kToplevel = 1 << 0,
     290             :     kEager = 1 << 1,
     291             :     kEval = 1 << 2,
     292             :     kStrictMode = 1 << 3,
     293             :     kNative = 1 << 4,
     294             :     kParseRestriction = 1 << 5,
     295             :     kModule = 1 << 6,
     296             :     kAllowLazyParsing = 1 << 7,
     297             :     kIsNamedExpression = 1 << 8,
     298             :     kLazyCompile = 1 << 9,
     299             :     kCollectTypeProfile = 1 << 10,
     300             :     kCoverageEnabled = 1 << 11,
     301             :     kBlockCoverageEnabled = 1 << 12,
     302             :     kIsAsmWasmBroken = 1 << 13,
     303             :     kOnBackgroundThread = 1 << 14,
     304             :     kWrappedAsFunction = 1 << 15,  // Implicitly wrapped as function.
     305             :     kAllowEvalCache = 1 << 16,
     306             :     kIsDeclaration = 1 << 17,
     307             :     kRequiresInstanceMembersInitializer = 1 << 18,
     308             :     kContainsAsmModule = 1 << 19,
     309             :     kMightAlwaysOpt = 1 << 20,
     310             :     kAllowLazyCompile = 1 << 21,
     311             :     kAllowNativeSyntax = 1 << 22,
     312             :     kAllowHarmonyPublicFields = 1 << 23,
     313             :     kAllowHarmonyStaticFields = 1 << 24,
     314             :     kAllowHarmonyDynamicImport = 1 << 25,
     315             :     kAllowHarmonyImportMeta = 1 << 26,
     316             :     kAllowHarmonyNumericSeparator = 1 << 27,
     317             :     kAllowHarmonyPrivateFields = 1 << 28,
     318             :     kAllowHarmonyPrivateMethods = 1 << 29,
     319             :     kIsOneshotIIFE = 1 << 30,
     320             :     kCollectSourcePositions = 1 << 31,
     321             :   };
     322             : 
     323             :   //------------- Inputs to parsing and scope analysis -----------------------
     324             :   std::unique_ptr<Zone> zone_;
     325             :   unsigned flags_;
     326             :   v8::Extension* extension_;
     327             :   DeclarationScope* script_scope_;
     328             :   uintptr_t stack_limit_;
     329             :   uint64_t hash_seed_;
     330             :   FunctionKind function_kind_;
     331             :   int script_id_;
     332             :   int start_position_;
     333             :   int end_position_;
     334             :   int parameters_end_pos_;
     335             :   int function_literal_id_;
     336             :   int max_function_literal_id_;
     337             : 
     338             :   // TODO(titzer): Move handles out of ParseInfo.
     339             :   Handle<Script> script_;
     340             :   MaybeHandle<ScopeInfo> maybe_outer_scope_info_;
     341             : 
     342             :   //----------- Inputs+Outputs of parsing and scope analysis -----------------
     343             :   std::unique_ptr<Utf16CharacterStream> character_stream_;
     344             :   std::unique_ptr<ConsumedPreparseData> consumed_preparse_data_;
     345             :   std::unique_ptr<AstValueFactory> ast_value_factory_;
     346             :   const class AstStringConstants* ast_string_constants_;
     347             :   const AstRawString* function_name_;
     348             :   RuntimeCallStats* runtime_call_stats_;
     349             :   Logger* logger_;
     350             :   SourceRangeMap* source_range_map_;  // Used when block coverage is enabled.
     351             :   std::unique_ptr<ParallelTasks> parallel_tasks_;
     352             : 
     353             :   //----------- Output of parsing and scope analysis ------------------------
     354             :   FunctionLiteral* literal_;
     355             :   PendingCompilationErrorHandler pending_error_handler_;
     356             : 
     357     3330534 :   void SetFlag(Flag f) { flags_ |= f; }
     358    49314223 :   void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; }
     359    87962804 :   bool GetFlag(Flag f) const { return (flags_ & f) != 0; }
     360             : };
     361             : 
     362             : }  // namespace internal
     363             : }  // namespace v8
     364             : 
     365             : #endif  // V8_PARSING_PARSE_INFO_H_

Generated by: LCOV version 1.10