• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_PREPARSED_SCOPE_DATA_H_
6 #define V8_PARSING_PREPARSED_SCOPE_DATA_H_
7 
8 #include <vector>
9 
10 #include "src/globals.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 class PreParsedScopeData {
16  public:
PreParsedScopeData()17   PreParsedScopeData() {}
~PreParsedScopeData()18   ~PreParsedScopeData() {}
19 
20   // Whether the scope has variables whose context allocation or
21   // maybeassignedness we need to decide based on preparsed scope data.
22   static bool HasVariablesWhichNeedAllocationData(Scope* scope);
23 
24   class ScopeScope {
25    public:
26     ScopeScope(PreParsedScopeData* data, ScopeType scope_type,
27                int start_position, int end_position);
28     ~ScopeScope();
29 
30     void MaybeAddVariable(Variable* var);
31 
32    private:
33     PreParsedScopeData* data_;
34     size_t index_in_data_;
35     ScopeScope* previous_scope_;
36 
37     int inner_scope_count_ = 0;
38     int variable_count_ = 0;
39     bool got_data_ = false;
40     DISALLOW_COPY_AND_ASSIGN(ScopeScope);
41   };
42 
43  private:
44   friend class ScopeTestHelper;
45 
46   // TODO(marja): Make the backing store more efficient once we know exactly
47   // what data is needed.
48   std::vector<int> backing_store_;
49   ScopeScope* current_scope_ = nullptr;
50 
51   DISALLOW_COPY_AND_ASSIGN(PreParsedScopeData);
52 };
53 
54 }  // namespace internal
55 }  // namespace v8
56 
57 #endif  // V8_PARSING_PREPARSED_SCOPE_DATA_H_
58