summaryrefslogtreecommitdiff
path: root/deps/v8/src/parsing/preparse-data.h
blob: 0e40c76927818e3ea46435ee84ea1d789f54fbd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2011 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_PARSING_PREPARSE_DATA_H_
#define V8_PARSING_PREPARSE_DATA_H_

#include <unordered_map>

#include "src/allocation.h"
#include "src/base/hashmap.h"
#include "src/collector.h"
#include "src/messages.h"
namespace v8 {
namespace internal {

class PreParserLogger final {
 public:
  PreParserLogger()
      : end_(-1),
        num_parameters_(-1),
        num_inner_functions_(-1) {}

  void LogFunction(int end, int num_parameters, int num_inner_functions) {
    end_ = end;
    num_parameters_ = num_parameters;
    num_inner_functions_ = num_inner_functions;
  }

  int end() const { return end_; }
  int num_parameters() const {
    return num_parameters_;
  }
  int num_inner_functions() const { return num_inner_functions_; }

 private:
  int end_;
  // For function entries.
  int num_parameters_;
  int num_inner_functions_;
};

class PreParseData final {
 public:
  struct FunctionData {
    int end;
    int num_parameters;
    int num_inner_functions;
    LanguageMode language_mode;
    bool uses_super_property : 1;

    FunctionData() : end(kNoSourcePosition) {}

    FunctionData(int end, int num_parameters, int num_inner_functions,
                 LanguageMode language_mode, bool uses_super_property)
        : end(end),
          num_parameters(num_parameters),
          num_inner_functions(num_inner_functions),
          language_mode(language_mode),
          uses_super_property(uses_super_property) {}

    bool is_valid() const {
      DCHECK_IMPLIES(end < 0, end == kNoSourcePosition);
      return end != kNoSourcePosition;
    }
  };

  FunctionData GetFunctionData(int start) const;
  void AddFunctionData(int start, FunctionData&& data);
  void AddFunctionData(int start, const FunctionData& data);
  size_t size() const;

  typedef std::unordered_map<int, FunctionData>::const_iterator const_iterator;
  const_iterator begin() const;
  const_iterator end() const;

 private:
  std::unordered_map<int, FunctionData> functions_;
};

}  // namespace internal
}  // namespace v8.

#endif  // V8_PARSING_PREPARSE_DATA_H_