Chromium Code Reviews| 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // Allocate parameters and local variables, either in the local frame or | 173 // Allocate parameters and local variables, either in the local frame or |
| 174 // in the context(s). | 174 // in the context(s). |
| 175 LocalScope* context_owner = NULL; // No context needed yet. | 175 LocalScope* context_owner = NULL; // No context needed yet. |
| 176 int next_free_frame_index = | 176 int next_free_frame_index = |
| 177 scope->AllocateVariables(first_parameter_index_, | 177 scope->AllocateVariables(first_parameter_index_, |
| 178 num_params, | 178 num_params, |
| 179 first_stack_local_index_, | 179 first_stack_local_index_, |
| 180 scope, | 180 scope, |
| 181 &context_owner); | 181 &context_owner); |
| 182 | 182 |
| 183 // Allocate a local variable to save the current context when we call into | |
|
hausner
2013/02/07 17:00:45
Can we allocate this variable only when really nee
siva
2013/02/07 22:08:31
Changed this to allocate only when needed followin
| |
| 184 // any closure function as the call will destroy the current context. | |
| 185 LocalVariable* context_var = | |
| 186 new LocalVariable(function().token_pos(), | |
| 187 Symbols::SavedCurrentContextVar(), | |
| 188 Type::ZoneHandle(Type::DynamicType())); | |
| 189 context_var->set_index(next_free_frame_index--); | |
| 190 scope->AddVariable(context_var); | |
| 191 set_saved_current_context_var(context_var); | |
| 192 | |
| 183 // If this function allocates context variables, but none of its enclosing | 193 // If this function allocates context variables, but none of its enclosing |
| 184 // functions do, the context on entry is not linked as parent of the allocated | 194 // functions do, the context on entry is not linked as parent of the allocated |
| 185 // context but saved on entry and restored on exit as to prevent memory leaks. | 195 // context but saved on entry and restored on exit as to prevent memory leaks. |
| 186 // Add and allocate a local variable to this purpose. | 196 // Add and allocate a local variable to this purpose. |
| 187 if (context_owner != NULL) { | 197 if (context_owner != NULL) { |
| 188 const ContextScope& context_scope = | 198 const ContextScope& context_scope = |
| 189 ContextScope::Handle(function().context_scope()); | 199 ContextScope::Handle(function().context_scope()); |
| 190 if (context_scope.IsNull() || (context_scope.num_variables() == 0)) { | 200 if (context_scope.IsNull() || (context_scope.num_variables() == 0)) { |
| 191 LocalVariable* context_var = | 201 LocalVariable* context_var = |
| 192 new LocalVariable(function().token_pos(), | 202 new LocalVariable(function().token_pos(), |
| (...skipping 5738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5931 ASSERT(node->IsJumpNode()); | 5941 ASSERT(node->IsJumpNode()); |
| 5932 node->AsJumpNode()->AddInlinedFinallyNode(finally_node); | 5942 node->AsJumpNode()->AddInlinedFinallyNode(finally_node); |
| 5933 } | 5943 } |
| 5934 } | 5944 } |
| 5935 | 5945 |
| 5936 | 5946 |
| 5937 AstNode* Parser::ParseTryStatement(String* label_name) { | 5947 AstNode* Parser::ParseTryStatement(String* label_name) { |
| 5938 TRACE_PARSER("ParseTryStatement"); | 5948 TRACE_PARSER("ParseTryStatement"); |
| 5939 | 5949 |
| 5940 // We create three stack slots for exceptions here: | 5950 // We create three stack slots for exceptions here: |
| 5941 // ':saved_context_var' - Used to save the context before start of the try | 5951 // ':saved_try_context_var' - Used to save the context before start of the try |
| 5942 // block. The context register is restored from this | 5952 // block. The context register is restored from |
| 5943 // slot before processing the catch block handler. | 5953 // this slot before processing the catch block |
| 5954 // handler. | |
| 5944 // ':exception_var' - Used to save the current exception object that was | 5955 // ':exception_var' - Used to save the current exception object that was |
| 5945 // thrown. | 5956 // thrown. |
| 5946 // ':stacktrace_var' - Used to save the current stack trace object into which | 5957 // ':stacktrace_var' - Used to save the current stack trace object into which |
| 5947 // the stack trace was copied into when an exception was | 5958 // the stack trace was copied into when an exception was |
| 5948 // thrown. | 5959 // thrown. |
| 5949 // :exception_var and :stacktrace_var get set with the exception object | 5960 // :exception_var and :stacktrace_var get set with the exception object |
| 5950 // and the stacktrace object when an exception is thrown. | 5961 // and the stacktrace object when an exception is thrown. |
| 5951 // These three implicit variables can never be captured variables. | 5962 // These three implicit variables can never be captured variables. |
| 5952 LocalVariable* context_var = | 5963 LocalVariable* context_var = |
| 5953 current_block_->scope->LocalLookupVariable(Symbols::SavedContextVar()); | 5964 current_block_->scope->LocalLookupVariable(Symbols::SavedTryContextVar()); |
| 5954 if (context_var == NULL) { | 5965 if (context_var == NULL) { |
| 5955 context_var = new LocalVariable(TokenPos(), | 5966 context_var = new LocalVariable(TokenPos(), |
| 5956 Symbols::SavedContextVar(), | 5967 Symbols::SavedTryContextVar(), |
| 5957 Type::ZoneHandle(Type::DynamicType())); | 5968 Type::ZoneHandle(Type::DynamicType())); |
| 5958 current_block_->scope->AddVariable(context_var); | 5969 current_block_->scope->AddVariable(context_var); |
| 5959 } | 5970 } |
| 5960 LocalVariable* catch_excp_var = | 5971 LocalVariable* catch_excp_var = |
| 5961 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); | 5972 current_block_->scope->LocalLookupVariable(Symbols::ExceptionVar()); |
| 5962 if (catch_excp_var == NULL) { | 5973 if (catch_excp_var == NULL) { |
| 5963 catch_excp_var = new LocalVariable(TokenPos(), | 5974 catch_excp_var = new LocalVariable(TokenPos(), |
| 5964 Symbols::ExceptionVar(), | 5975 Symbols::ExceptionVar(), |
| 5965 Type::ZoneHandle(Type::DynamicType())); | 5976 Type::ZoneHandle(Type::DynamicType())); |
| 5966 current_block_->scope->AddVariable(catch_excp_var); | 5977 current_block_->scope->AddVariable(catch_excp_var); |
| (...skipping 3792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9759 void Parser::SkipQualIdent() { | 9770 void Parser::SkipQualIdent() { |
| 9760 ASSERT(IsIdentifier()); | 9771 ASSERT(IsIdentifier()); |
| 9761 ConsumeToken(); | 9772 ConsumeToken(); |
| 9762 if (CurrentToken() == Token::kPERIOD) { | 9773 if (CurrentToken() == Token::kPERIOD) { |
| 9763 ConsumeToken(); // Consume the kPERIOD token. | 9774 ConsumeToken(); // Consume the kPERIOD token. |
| 9764 ExpectIdentifier("identifier expected after '.'"); | 9775 ExpectIdentifier("identifier expected after '.'"); |
| 9765 } | 9776 } |
| 9766 } | 9777 } |
| 9767 | 9778 |
| 9768 } // namespace dart | 9779 } // namespace dart |
| OLD | NEW |