1// Copyright 2018 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#include "src/unoptimized-compilation-info.h"
6
7#include "src/ast/ast.h"
8#include "src/ast/scopes.h"
9#include "src/debug/debug.h"
10#include "src/isolate.h"
11#include "src/objects-inl.h"
12#include "src/parsing/parse-info.h"
13#include "src/source-position.h"
14
15namespace v8 {
16namespace internal {
17
18UnoptimizedCompilationInfo::UnoptimizedCompilationInfo(Zone* zone,
19 ParseInfo* parse_info,
20 FunctionLiteral* literal)
21 : flags_(0), zone_(zone), feedback_vector_spec_(zone) {
22 // NOTE: The parse_info passed here represents the global information gathered
23 // during parsing, but does not represent specific details of the actual
24 // function literal being compiled for this OptimizedCompilationInfo. As such,
25 // parse_info->literal() might be different from literal, and only global
26 // details of the script being parsed are relevant to this
27 // OptimizedCompilationInfo.
28 DCHECK_NOT_NULL(literal);
29 literal_ = literal;
30 source_range_map_ = parse_info->source_range_map();
31
32 if (parse_info->is_eval()) MarkAsEval();
33 if (parse_info->collect_type_profile()) MarkAsCollectTypeProfile();
34 if (parse_info->might_always_opt()) MarkAsMightAlwaysOpt();
35 if (parse_info->collect_source_positions()) {
36 MarkAsForceCollectSourcePositions();
37 }
38}
39
40DeclarationScope* UnoptimizedCompilationInfo::scope() const {
41 DCHECK_NOT_NULL(literal_);
42 return literal_->scope();
43}
44
45int UnoptimizedCompilationInfo::num_parameters() const {
46 return scope()->num_parameters();
47}
48
49int UnoptimizedCompilationInfo::num_parameters_including_this() const {
50 return scope()->num_parameters() + 1;
51}
52
53SourcePositionTableBuilder::RecordingMode
54UnoptimizedCompilationInfo::SourcePositionRecordingMode() const {
55 if (collect_source_positions()) {
56 return SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
57 }
58
59 // Always collect source positions for functions that cannot be lazily
60 // compiled, e.g. class member initializer functions.
61 return !literal_->AllowsLazyCompilation()
62 ? SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS
63 : SourcePositionTableBuilder::LAZY_SOURCE_POSITIONS;
64}
65
66} // namespace internal
67} // namespace v8
68