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 "src/allocation.h"
9 #include "src/base/hashmap.h"
10 #include "src/collector.h"
11 #include "src/messages.h"
12 #include "src/parsing/preparse-data-format.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class ScriptData {
18  public:
19   ScriptData(const byte* data, int length);
~ScriptData()20   ~ScriptData() {
21     if (owns_data_) DeleteArray(data_);
22   }
23 
data()24   const byte* data() const { return data_; }
length()25   int length() const { return length_; }
rejected()26   bool rejected() const { return rejected_; }
27 
Reject()28   void Reject() { rejected_ = true; }
29 
AcquireDataOwnership()30   void AcquireDataOwnership() {
31     DCHECK(!owns_data_);
32     owns_data_ = true;
33   }
34 
ReleaseDataOwnership()35   void ReleaseDataOwnership() {
36     DCHECK(owns_data_);
37     owns_data_ = false;
38   }
39 
40  private:
41   bool owns_data_ : 1;
42   bool rejected_ : 1;
43   const byte* data_;
44   int length_;
45 
46   DISALLOW_COPY_AND_ASSIGN(ScriptData);
47 };
48 
49 class PreParserLogger final {
50  public:
PreParserLogger()51   PreParserLogger()
52       : end_(-1),
53         num_parameters_(-1),
54         function_length_(-1),
55         has_duplicate_parameters_(false) {}
56 
LogFunction(int end,int num_parameters,int function_length,bool has_duplicate_parameters,int literals,int properties)57   void LogFunction(int end, int num_parameters, int function_length,
58                    bool has_duplicate_parameters, int literals,
59                    int properties) {
60     end_ = end;
61     num_parameters_ = num_parameters;
62     function_length_ = function_length;
63     has_duplicate_parameters_ = has_duplicate_parameters;
64     literals_ = literals;
65     properties_ = properties;
66   }
67 
end()68   int end() const { return end_; }
num_parameters()69   int num_parameters() const {
70     return num_parameters_;
71   }
function_length()72   int function_length() const {
73     return function_length_;
74   }
has_duplicate_parameters()75   bool has_duplicate_parameters() const {
76     return has_duplicate_parameters_;
77   }
literals()78   int literals() const {
79     return literals_;
80   }
properties()81   int properties() const {
82     return properties_;
83   }
84 
85  private:
86   int end_;
87   // For function entries.
88   int num_parameters_;
89   int function_length_;
90   bool has_duplicate_parameters_;
91   int literals_;
92   int properties_;
93 };
94 
95 class ParserLogger final {
96  public:
97   ParserLogger();
98 
99   void LogFunction(int start, int end, int num_parameters, int function_length,
100                    bool has_duplicate_parameters, int literals, int properties,
101                    LanguageMode language_mode, bool uses_super_property,
102                    bool calls_eval);
103 
104   ScriptData* GetScriptData();
105 
106  private:
107   Collector<unsigned> function_store_;
108   unsigned preamble_[PreparseDataConstants::kHeaderSize];
109 
110 #ifdef DEBUG
111   int prev_start_;
112 #endif
113 };
114 
115 
116 }  // namespace internal
117 }  // namespace v8.
118 
119 #endif  // V8_PARSING_PREPARSE_DATA_H_
120