aboutsummaryrefslogtreecommitdiff
path: root/src/parsing/preparsed-scope-data.h
blob: 72d1a717af6c344466f1c85c6cbf832e7ddc8ef7 (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
// Copyright 2017 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_PREPARSED_SCOPE_DATA_H_
#define V8_PARSING_PREPARSED_SCOPE_DATA_H_

#include <vector>

#include "src/globals.h"

namespace v8 {
namespace internal {

class PreParsedScopeData {
 public:
  PreParsedScopeData() {}
  ~PreParsedScopeData() {}

  // Whether the scope has variables whose context allocation or
  // maybeassignedness we need to decide based on preparsed scope data.
  static bool HasVariablesWhichNeedAllocationData(Scope* scope);

  class ScopeScope {
   public:
    ScopeScope(PreParsedScopeData* data, ScopeType scope_type,
               int start_position, int end_position);
    ~ScopeScope();

    void MaybeAddVariable(Variable* var);

   private:
    PreParsedScopeData* data_;
    size_t index_in_data_;
    ScopeScope* previous_scope_;

    int inner_scope_count_ = 0;
    int variable_count_ = 0;
    bool got_data_ = false;
    DISALLOW_COPY_AND_ASSIGN(ScopeScope);
  };

 private:
  friend class ScopeTestHelper;

  // TODO(marja): Make the backing store more efficient once we know exactly
  // what data is needed.
  std::vector<int> backing_store_;
  ScopeScope* current_scope_ = nullptr;

  DISALLOW_COPY_AND_ASSIGN(PreParsedScopeData);
};

}  // namespace internal
}  // namespace v8

#endif  // V8_PARSING_PREPARSED_SCOPE_DATA_H_