Line data Source code
1 : // Copyright 2011 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_PREPARSE_DATA_H_
6 : #define V8_PARSING_PREPARSE_DATA_H_
7 :
8 : #include <unordered_map>
9 :
10 : #include "src/allocation.h"
11 : #include "src/base/hashmap.h"
12 : #include "src/collector.h"
13 : #include "src/messages.h"
14 : #include "src/parsing/preparse-data-format.h"
15 :
16 : namespace v8 {
17 : namespace internal {
18 :
19 : class ScriptData {
20 : public:
21 : ScriptData(const byte* data, int length);
22 105 : ~ScriptData() {
23 1198 : if (owns_data_) DeleteArray(data_);
24 105 : }
25 :
26 90 : const byte* data() const { return data_; }
27 270 : int length() const { return length_; }
28 569 : bool rejected() const { return rejected_; }
29 :
30 85 : void Reject() { rejected_ = true; }
31 :
32 : void AcquireDataOwnership() {
33 : DCHECK(!owns_data_);
34 705 : owns_data_ = true;
35 : }
36 :
37 : void ReleaseDataOwnership() {
38 : DCHECK(owns_data_);
39 492 : owns_data_ = false;
40 : }
41 :
42 : private:
43 : bool owns_data_ : 1;
44 : bool rejected_ : 1;
45 : const byte* data_;
46 : int length_;
47 :
48 : DISALLOW_COPY_AND_ASSIGN(ScriptData);
49 : };
50 :
51 : class PreParserLogger final {
52 : public:
53 : PreParserLogger()
54 : : end_(-1),
55 : num_parameters_(-1),
56 405607 : num_inner_functions_(-1) {}
57 :
58 : void LogFunction(int end, int num_parameters, int num_inner_functions) {
59 1386477 : end_ = end;
60 1386477 : num_parameters_ = num_parameters;
61 1386477 : num_inner_functions_ = num_inner_functions;
62 : }
63 :
64 : int end() const { return end_; }
65 : int num_parameters() const {
66 : return num_parameters_;
67 : }
68 : int num_inner_functions() const { return num_inner_functions_; }
69 :
70 : private:
71 : int end_;
72 : // For function entries.
73 : int num_parameters_;
74 : int num_inner_functions_;
75 : };
76 :
77 2263500 : class ParserLogger final {
78 : public:
79 : ParserLogger();
80 :
81 : void LogFunction(int start, int end, int num_parameters,
82 : LanguageMode language_mode, bool uses_super_property,
83 : int num_inner_functions);
84 :
85 : ScriptData* GetScriptData();
86 :
87 : private:
88 : Collector<unsigned> function_store_;
89 : unsigned preamble_[PreparseDataConstants::kHeaderSize];
90 :
91 : #ifdef DEBUG
92 : int prev_start_;
93 : #endif
94 : };
95 :
96 4842053 : class PreParseData final {
97 : public:
98 : struct FunctionData {
99 : int end;
100 : int num_parameters;
101 : int num_inner_functions;
102 : LanguageMode language_mode;
103 : bool uses_super_property : 1;
104 :
105 25667 : FunctionData() : end(-1) {}
106 :
107 : FunctionData(int end, int num_parameters, int num_inner_functions,
108 : LanguageMode language_mode, bool uses_super_property)
109 : : end(end),
110 : num_parameters(num_parameters),
111 : num_inner_functions(num_inner_functions),
112 : language_mode(language_mode),
113 25667 : uses_super_property(uses_super_property) {}
114 :
115 : bool is_valid() const { return end > 0; }
116 : };
117 :
118 : FunctionData GetFunctionData(int start) const;
119 : void AddFunctionData(int start, FunctionData&& data);
120 : void AddFunctionData(int start, const FunctionData& data);
121 : size_t size() const;
122 :
123 : typedef std::unordered_map<int, FunctionData>::const_iterator const_iterator;
124 : const_iterator begin() const;
125 : const_iterator end() const;
126 :
127 : private:
128 : std::unordered_map<int, FunctionData> functions_;
129 : };
130 :
131 : } // namespace internal
132 : } // namespace v8.
133 :
134 : #endif // V8_PARSING_PREPARSE_DATA_H_
|