11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/codegen/unoptimized-compilation-info.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/ast/ast.h"
81cb0ef41Sopenharmony_ci#include "src/ast/scopes.h"
91cb0ef41Sopenharmony_ci#include "src/codegen/source-position.h"
101cb0ef41Sopenharmony_ci#include "src/debug/debug.h"
111cb0ef41Sopenharmony_ci#include "src/execution/isolate.h"
121cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
131cb0ef41Sopenharmony_ci#include "src/parsing/parse-info.h"
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cinamespace v8 {
161cb0ef41Sopenharmony_cinamespace internal {
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciUnoptimizedCompilationInfo::UnoptimizedCompilationInfo(Zone* zone,
191cb0ef41Sopenharmony_ci                                                       ParseInfo* parse_info,
201cb0ef41Sopenharmony_ci                                                       FunctionLiteral* literal)
211cb0ef41Sopenharmony_ci    : flags_(parse_info->flags()),
221cb0ef41Sopenharmony_ci      dispatcher_(parse_info->dispatcher()),
231cb0ef41Sopenharmony_ci      character_stream_(parse_info->character_stream()),
241cb0ef41Sopenharmony_ci      feedback_vector_spec_(zone) {
251cb0ef41Sopenharmony_ci  // NOTE: The parse_info passed here represents the global information gathered
261cb0ef41Sopenharmony_ci  // during parsing, but does not represent specific details of the actual
271cb0ef41Sopenharmony_ci  // function literal being compiled for this OptimizedCompilationInfo. As such,
281cb0ef41Sopenharmony_ci  // parse_info->literal() might be different from literal, and only global
291cb0ef41Sopenharmony_ci  // details of the script being parsed are relevant to this
301cb0ef41Sopenharmony_ci  // OptimizedCompilationInfo.
311cb0ef41Sopenharmony_ci  DCHECK_NOT_NULL(literal);
321cb0ef41Sopenharmony_ci  literal_ = literal;
331cb0ef41Sopenharmony_ci  source_range_map_ = parse_info->source_range_map();
341cb0ef41Sopenharmony_ci}
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciDeclarationScope* UnoptimizedCompilationInfo::scope() const {
371cb0ef41Sopenharmony_ci  DCHECK_NOT_NULL(literal_);
381cb0ef41Sopenharmony_ci  return literal_->scope();
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciint UnoptimizedCompilationInfo::num_parameters() const {
421cb0ef41Sopenharmony_ci  return scope()->num_parameters();
431cb0ef41Sopenharmony_ci}
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciint UnoptimizedCompilationInfo::num_parameters_including_this() const {
461cb0ef41Sopenharmony_ci  return scope()->num_parameters() + 1;
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ciSourcePositionTableBuilder::RecordingMode
501cb0ef41Sopenharmony_ciUnoptimizedCompilationInfo::SourcePositionRecordingMode() const {
511cb0ef41Sopenharmony_ci  if (flags().collect_source_positions()) {
521cb0ef41Sopenharmony_ci    return SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  // Always collect source positions for functions that cannot be lazily
561cb0ef41Sopenharmony_ci  // compiled, e.g. class member initializer functions.
571cb0ef41Sopenharmony_ci  return !literal_->AllowsLazyCompilation()
581cb0ef41Sopenharmony_ci             ? SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS
591cb0ef41Sopenharmony_ci             : SourcePositionTableBuilder::LAZY_SOURCE_POSITIONS;
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci}  // namespace internal
631cb0ef41Sopenharmony_ci}  // namespace v8
64