Line data Source code
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 :
15 : namespace v8 {
16 : namespace internal {
17 :
18 2100420 : UnoptimizedCompilationInfo::UnoptimizedCompilationInfo(Zone* zone,
19 : ParseInfo* parse_info,
20 : FunctionLiteral* literal)
21 2100420 : : 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 2100434 : literal_ = literal;
30 2100434 : source_range_map_ = parse_info->source_range_map();
31 :
32 2100434 : if (parse_info->is_eval()) MarkAsEval();
33 2100434 : if (parse_info->is_native()) MarkAsNative();
34 2100434 : if (parse_info->collect_type_profile()) MarkAsCollectTypeProfile();
35 2100434 : if (parse_info->might_always_opt()) MarkAsMightAlwaysOpt();
36 2100434 : if (parse_info->collect_source_positions()) {
37 : MarkAsForceCollectSourcePositions();
38 : }
39 2100434 : }
40 :
41 8365314 : DeclarationScope* UnoptimizedCompilationInfo::scope() const {
42 : DCHECK_NOT_NULL(literal_);
43 10462001 : return literal_->scope();
44 : }
45 :
46 0 : int UnoptimizedCompilationInfo::num_parameters() const {
47 0 : return scope()->num_parameters();
48 : }
49 :
50 2096687 : int UnoptimizedCompilationInfo::num_parameters_including_this() const {
51 2096687 : return scope()->num_parameters() + 1;
52 : }
53 :
54 : SourcePositionTableBuilder::RecordingMode
55 2096680 : UnoptimizedCompilationInfo::SourcePositionRecordingMode() const {
56 2096680 : if (is_native()) {
57 : DCHECK(!collect_source_positions());
58 : return SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS;
59 : }
60 :
61 2096680 : if (collect_source_positions()) {
62 : return SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
63 : }
64 :
65 : // Always collect source positions for functions that cannot be lazily
66 : // compiled, e.g. class member initializer functions.
67 20 : return !literal_->AllowsLazyCompilation()
68 : ? SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS
69 20 : : SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS;
70 : }
71 :
72 : } // namespace internal
73 120216 : } // namespace v8
|