| 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 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 LocalScope* context_owner = NULL; // No context needed yet. | 186 LocalScope* context_owner = NULL; // No context needed yet. |
| 187 bool found_captured_variables = false; | 187 bool found_captured_variables = false; |
| 188 int next_free_frame_index = | 188 int next_free_frame_index = |
| 189 scope->AllocateVariables(first_parameter_index_, | 189 scope->AllocateVariables(first_parameter_index_, |
| 190 num_params, | 190 num_params, |
| 191 first_stack_local_index_, | 191 first_stack_local_index_, |
| 192 scope, | 192 scope, |
| 193 &context_owner, | 193 &context_owner, |
| 194 &found_captured_variables); | 194 &found_captured_variables); |
| 195 | 195 |
| 196 // We save the entry context for a function when... | |
| 197 // | |
| 198 // - some variable in the function is captured by nested functions, and | |
| 199 // - the function does not capture any variables from parent functions. | |
| 200 // | |
| 201 // We used to link to the parent context in these cases, but this | |
| 202 // had the effect of unintentionally retaining parent contexts which | |
| 203 // would never be accessed. By breaking the context chain at this | |
| 204 // point, we allow these outer contexts to be collected. | |
| 205 if (found_captured_variables) { | |
| 206 const ContextScope& context_scope = | |
| 207 ContextScope::Handle(function().context_scope()); | |
| 208 if (context_scope.IsNull() || (context_scope.num_variables() == 0)) { | |
| 209 // Allocate a local variable for saving the entry context. | |
| 210 LocalVariable* context_var = | |
| 211 new LocalVariable(function().token_pos(), | |
| 212 Symbols::SavedEntryContextVar(), | |
| 213 Type::ZoneHandle(Type::DynamicType())); | |
| 214 context_var->set_index(next_free_frame_index--); | |
| 215 scope->AddVariable(context_var); | |
| 216 set_saved_entry_context_var(context_var); | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 // Frame indices are relative to the frame pointer and are decreasing. | 196 // Frame indices are relative to the frame pointer and are decreasing. |
| 221 ASSERT(next_free_frame_index <= first_stack_local_index_); | 197 ASSERT(next_free_frame_index <= first_stack_local_index_); |
| 222 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; | 198 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; |
| 223 } | 199 } |
| 224 | 200 |
| 225 | 201 |
| 226 struct CatchParamDesc { | 202 struct CatchParamDesc { |
| 227 CatchParamDesc() | 203 CatchParamDesc() |
| 228 : token_pos(0), type(NULL), name(NULL), var(NULL) { } | 204 : token_pos(0), type(NULL), name(NULL), var(NULL) { } |
| 229 intptr_t token_pos; | 205 intptr_t token_pos; |
| (...skipping 11698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11928 void Parser::SkipQualIdent() { | 11904 void Parser::SkipQualIdent() { |
| 11929 ASSERT(IsIdentifier()); | 11905 ASSERT(IsIdentifier()); |
| 11930 ConsumeToken(); | 11906 ConsumeToken(); |
| 11931 if (CurrentToken() == Token::kPERIOD) { | 11907 if (CurrentToken() == Token::kPERIOD) { |
| 11932 ConsumeToken(); // Consume the kPERIOD token. | 11908 ConsumeToken(); // Consume the kPERIOD token. |
| 11933 ExpectIdentifier("identifier expected after '.'"); | 11909 ExpectIdentifier("identifier expected after '.'"); |
| 11934 } | 11910 } |
| 11935 } | 11911 } |
| 11936 | 11912 |
| 11937 } // namespace dart | 11913 } // namespace dart |
| OLD | NEW |