OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_SCOPES_H_ | 5 #ifndef VM_SCOPES_H_ |
6 #define VM_SCOPES_H_ | 6 #define VM_SCOPES_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class LocalVariable : public ZoneAllocated { | 22 class LocalVariable : public ZoneAllocated { |
23 public: | 23 public: |
24 LocalVariable(intptr_t token_pos, | 24 LocalVariable(intptr_t token_pos, |
25 const String& name, | 25 const String& name, |
26 const AbstractType& type) | 26 const AbstractType& type) |
27 : token_pos_(token_pos), | 27 : token_pos_(token_pos), |
28 name_(name), | 28 name_(name), |
29 owner_(NULL), | 29 owner_(NULL), |
30 type_(type), | 30 type_(type), |
| 31 const_value_(NULL), |
31 is_final_(false), | 32 is_final_(false), |
32 is_captured_(false), | 33 is_captured_(false), |
33 is_invisible_(false), | 34 is_invisible_(false), |
34 index_(LocalVariable::kUnitializedIndex) { | 35 index_(LocalVariable::kUnitializedIndex) { |
35 ASSERT(type.IsZoneHandle()); | 36 ASSERT(type.IsZoneHandle()); |
36 ASSERT(type.IsFinalized()); | 37 ASSERT(type.IsFinalized()); |
37 } | 38 } |
38 | 39 |
39 intptr_t token_pos() const { return token_pos_; } | 40 intptr_t token_pos() const { return token_pos_; } |
40 const String& name() const { return name_; } | 41 const String& name() const { return name_; } |
(...skipping 23 matching lines...) Expand all Loading... |
64 void set_index(int index) { | 65 void set_index(int index) { |
65 ASSERT(!HasIndex()); | 66 ASSERT(!HasIndex()); |
66 ASSERT(index != kUnitializedIndex); | 67 ASSERT(index != kUnitializedIndex); |
67 index_ = index; | 68 index_ = index; |
68 } | 69 } |
69 | 70 |
70 void set_invisible(bool value) { | 71 void set_invisible(bool value) { |
71 is_invisible_ = value; | 72 is_invisible_ = value; |
72 } | 73 } |
73 | 74 |
| 75 bool IsConst() const { |
| 76 return const_value_ != NULL; |
| 77 } |
| 78 |
| 79 void SetConstValue(const Instance& value) { |
| 80 ASSERT(value.IsZoneHandle()); |
| 81 const_value_ = &value; |
| 82 } |
| 83 |
| 84 const Instance* ConstValue() const { |
| 85 ASSERT(IsConst()); |
| 86 return const_value_; |
| 87 } |
| 88 |
74 bool Equals(const LocalVariable& other) const; | 89 bool Equals(const LocalVariable& other) const; |
75 | 90 |
76 // Map the frame index to a bit-vector index. Assumes the variable is | 91 // Map the frame index to a bit-vector index. Assumes the variable is |
77 // allocated to the frame. | 92 // allocated to the frame. |
78 // var_count is the total number of stack-allocated variables including | 93 // var_count is the total number of stack-allocated variables including |
79 // all parameters. | 94 // all parameters. |
80 int BitIndexIn(intptr_t var_count) const; | 95 int BitIndexIn(intptr_t var_count) const; |
81 | 96 |
82 private: | 97 private: |
83 static const int kUnitializedIndex = INT_MIN; | 98 static const int kUnitializedIndex = INT_MIN; |
84 | 99 |
85 const intptr_t token_pos_; | 100 const intptr_t token_pos_; |
86 const String& name_; | 101 const String& name_; |
87 LocalScope* owner_; // Local scope declaring this variable. | 102 LocalScope* owner_; // Local scope declaring this variable. |
88 | 103 |
89 const AbstractType& type_; // Declaration type of local variable. | 104 const AbstractType& type_; // Declaration type of local variable. |
90 | 105 |
| 106 const Instance* const_value_; // NULL or compile-time const value. |
| 107 |
91 bool is_final_; // If true, this variable is readonly. | 108 bool is_final_; // If true, this variable is readonly. |
92 bool is_captured_; // If true, this variable lives in the context, otherwise | 109 bool is_captured_; // If true, this variable lives in the context, otherwise |
93 // in the stack frame. | 110 // in the stack frame. |
94 bool is_invisible_; | 111 bool is_invisible_; |
95 int index_; // Allocation index in words relative to frame pointer (if not | 112 int index_; // Allocation index in words relative to frame pointer (if not |
96 // captured), or relative to the context pointer (if captured). | 113 // captured), or relative to the context pointer (if captured). |
97 | 114 |
98 friend class LocalScope; | 115 friend class LocalScope; |
99 DISALLOW_COPY_AND_ASSIGN(LocalVariable); | 116 DISALLOW_COPY_AND_ASSIGN(LocalVariable); |
100 }; | 117 }; |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 intptr_t end_token_pos_; // Token index of end of scope. | 361 intptr_t end_token_pos_; // Token index of end of scope. |
345 GrowableArray<LocalVariable*> variables_; | 362 GrowableArray<LocalVariable*> variables_; |
346 GrowableArray<SourceLabel*> labels_; | 363 GrowableArray<SourceLabel*> labels_; |
347 | 364 |
348 DISALLOW_COPY_AND_ASSIGN(LocalScope); | 365 DISALLOW_COPY_AND_ASSIGN(LocalScope); |
349 }; | 366 }; |
350 | 367 |
351 } // namespace dart | 368 } // namespace dart |
352 | 369 |
353 #endif // VM_SCOPES_H_ | 370 #endif // VM_SCOPES_H_ |
OLD | NEW |