Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: runtime/vm/scopes.cc

Issue 293013005: Fix issue 18435 (2nd attempt). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/scopes.h ('k') | tests/language/regress_18435_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "vm/scopes.h" 5 #include "vm/scopes.h"
6 6
7 #include "vm/object.h" 7 #include "vm/object.h"
8 #include "vm/stack_frame.h" 8 #include "vm/stack_frame.h"
9 #include "vm/symbols.h" 9 #include "vm/symbols.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 variables_.Add(variable); 59 variables_.Add(variable);
60 if (variable->owner() == NULL) { 60 if (variable->owner() == NULL) {
61 // Variables must be added to their owner scope first. Subsequent calls 61 // Variables must be added to their owner scope first. Subsequent calls
62 // to 'add' treat the variable as an alias. 62 // to 'add' treat the variable as an alias.
63 variable->set_owner(this); 63 variable->set_owner(this);
64 } 64 }
65 return true; 65 return true;
66 } 66 }
67 67
68 68
69 bool LocalScope::InsertParameterAt(intptr_t pos, LocalVariable* parameter) {
70 ASSERT(parameter != NULL);
71 if (LocalLookupVariable(parameter->name()) != NULL) {
72 return false;
73 }
74 variables_.InsertAt(pos, parameter);
75 // InsertParameterAt is not used to add aliases of parameters.
76 ASSERT(parameter->owner() == NULL);
77 parameter->set_owner(this);
78 return true;
79 }
80
81
69 bool LocalScope::AddLabel(SourceLabel* label) { 82 bool LocalScope::AddLabel(SourceLabel* label) {
70 if (LocalLookupLabel(label->name()) != NULL) { 83 if (LocalLookupLabel(label->name()) != NULL) {
71 return false; 84 return false;
72 } 85 }
73 labels_.Add(label); 86 labels_.Add(label);
74 if (label->owner() == NULL) { 87 if (label->owner() == NULL) {
75 // Labels must be added to their owner scope first. Subsequent calls 88 // Labels must be added to their owner scope first. Subsequent calls
76 // to 'add' treat the label as an alias. 89 // to 'add' treat the label as an alias.
77 label->set_owner(this); 90 label->set_owner(this);
78 } 91 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (loop_level() > loop_owner->loop_level()) { 177 if (loop_level() > loop_owner->loop_level()) {
165 loop_owner = this; 178 loop_owner = this;
166 } 179 }
167 // Parameters must be listed first and must all appear in the top scope. 180 // Parameters must be listed first and must all appear in the top scope.
168 ASSERT(num_parameters <= num_variables()); 181 ASSERT(num_parameters <= num_variables());
169 int pos = 0; // Current variable position. 182 int pos = 0; // Current variable position.
170 int frame_index = first_parameter_index; // Current free frame index. 183 int frame_index = first_parameter_index; // Current free frame index.
171 while (pos < num_parameters) { 184 while (pos < num_parameters) {
172 LocalVariable* parameter = VariableAt(pos); 185 LocalVariable* parameter = VariableAt(pos);
173 pos++; 186 pos++;
187 // Parsing formal parameter default values may add local variable aliases
188 // to the local scope before the formal parameters are added. However,
189 // the parameters get inserted in front of the aliases, therefore, no
190 // aliases can be encountered among the first num_parameters variables.
174 ASSERT(parameter->owner() == this); 191 ASSERT(parameter->owner() == this);
175 if (parameter->is_captured()) { 192 if (parameter->is_captured()) {
176 // A captured parameter has a slot allocated in the frame and one in the 193 // A captured parameter has a slot allocated in the frame and one in the
177 // context, where it gets copied to. The parameter index reflects the 194 // context, where it gets copied to. The parameter index reflects the
178 // context allocation index. 195 // context allocation index.
179 frame_index--; 196 frame_index--;
180 loop_owner->AllocateContextVariable(parameter, context_owner); 197 loop_owner->AllocateContextVariable(parameter, context_owner);
181 *found_captured_variables = true; 198 *found_captured_variables = true;
182 } else { 199 } else {
183 parameter->set_index(frame_index--); 200 parameter->set_index(frame_index--);
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 return fixed_parameter_count - (index() - kParamEndSlotFromFp); 648 return fixed_parameter_count - (index() - kParamEndSlotFromFp);
632 } else { 649 } else {
633 // Shift negative indexes so that the lowest one is 0 (they are still 650 // Shift negative indexes so that the lowest one is 0 (they are still
634 // non-positive). 651 // non-positive).
635 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp); 652 return fixed_parameter_count - (index() - kFirstLocalSlotFromFp);
636 } 653 }
637 } 654 }
638 655
639 656
640 } // namespace dart 657 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/scopes.h ('k') | tests/language/regress_18435_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698