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