| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 } | 1115 } |
| 1116 return super_op; | 1116 return super_op; |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 | 1119 |
| 1120 AstNode* Parser::CreateImplicitClosureNode(const Function& func, | 1120 AstNode* Parser::CreateImplicitClosureNode(const Function& func, |
| 1121 intptr_t token_pos, | 1121 intptr_t token_pos, |
| 1122 AstNode* receiver) { | 1122 AstNode* receiver) { |
| 1123 Function& implicit_closure_function = | 1123 Function& implicit_closure_function = |
| 1124 Function::ZoneHandle(func.ImplicitClosureFunction()); | 1124 Function::ZoneHandle(func.ImplicitClosureFunction()); |
| 1125 if (receiver == NULL) { | 1125 if (receiver != NULL) { |
| 1126 return new ImplicitStaticClosureNode(token_pos, implicit_closure_function); | |
| 1127 } else { | |
| 1128 // If we create an implicit instance closure from inside a closure of a | 1126 // If we create an implicit instance closure from inside a closure of a |
| 1129 // parameterized class, make sure that the receiver is captured as | 1127 // parameterized class, make sure that the receiver is captured as |
| 1130 // instantiator. | 1128 // instantiator. |
| 1131 if (current_block_->scope->function_level() > 0) { | 1129 if (current_block_->scope->function_level() > 0) { |
| 1132 const Class& signature_class = Class::Handle(func.signature_class()); | 1130 const Class& signature_class = Class::Handle(func.signature_class()); |
| 1133 if (signature_class.IsParameterized()) { | 1131 if (signature_class.IsParameterized()) { |
| 1134 CaptureReceiver(); | 1132 CaptureReceiver(); |
| 1135 } | 1133 } |
| 1136 } | 1134 } |
| 1137 return new ImplicitInstanceClosureNode(token_pos, | |
| 1138 implicit_closure_function, | |
| 1139 receiver); | |
| 1140 } | 1135 } |
| 1136 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); |
| 1141 } | 1137 } |
| 1142 | 1138 |
| 1143 | 1139 |
| 1144 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { | 1140 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { |
| 1145 const intptr_t field_pos = token_index_; | 1141 const intptr_t field_pos = token_index_; |
| 1146 const Class& super_class = Class::Handle(current_class().SuperClass()); | 1142 const Class& super_class = Class::Handle(current_class().SuperClass()); |
| 1147 if (super_class.IsNull()) { | 1143 if (super_class.IsNull()) { |
| 1148 ErrorMsg("class '%s' does not have a superclass", | 1144 ErrorMsg("class '%s' does not have a superclass", |
| 1149 String::Handle(current_class().Name()).ToCString()); | 1145 String::Handle(current_class().Name()).ToCString()); |
| 1150 } | 1146 } |
| (...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 // captured. The captured variables will be recorded along with their | 3487 // captured. The captured variables will be recorded along with their |
| 3492 // allocation information in a Scope object stored in the function object. | 3488 // allocation information in a Scope object stored in the function object. |
| 3493 // This Scope object is then provided to the compiler when compiling the local | 3489 // This Scope object is then provided to the compiler when compiling the local |
| 3494 // function. It would be too early to record the captured variables here, | 3490 // function. It would be too early to record the captured variables here, |
| 3495 // since further closure functions may capture more variables. | 3491 // since further closure functions may capture more variables. |
| 3496 // This Scope object is constructed after all variables have been allocated. | 3492 // This Scope object is constructed after all variables have been allocated. |
| 3497 // The local scope of the parsed function can be pruned, since contained | 3493 // The local scope of the parsed function can be pruned, since contained |
| 3498 // variables are not relevant for the compilation of the enclosing function. | 3494 // variables are not relevant for the compilation of the enclosing function. |
| 3499 // This pruning is done by omitting to hook the local scope in its parent | 3495 // This pruning is done by omitting to hook the local scope in its parent |
| 3500 // scope in the constructor of LocalScope. | 3496 // scope in the constructor of LocalScope. |
| 3501 AstNode* closure = new ClosureNode(ident_pos, function, statements->scope()); | 3497 AstNode* closure = |
| 3498 new ClosureNode(ident_pos, function, NULL, statements->scope()); |
| 3502 | 3499 |
| 3503 if (function_variable == NULL) { | 3500 if (function_variable == NULL) { |
| 3504 ASSERT(is_literal); | 3501 ASSERT(is_literal); |
| 3505 return closure; | 3502 return closure; |
| 3506 } else { | 3503 } else { |
| 3507 AstNode* initialization = | 3504 AstNode* initialization = |
| 3508 new StoreLocalNode(ident_pos, *function_variable, closure); | 3505 new StoreLocalNode(ident_pos, *function_variable, closure); |
| 3509 return initialization; | 3506 return initialization; |
| 3510 } | 3507 } |
| 3511 } | 3508 } |
| (...skipping 3525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7037 } | 7034 } |
| 7038 | 7035 |
| 7039 | 7036 |
| 7040 void Parser::SkipNestedExpr() { | 7037 void Parser::SkipNestedExpr() { |
| 7041 const bool saved_mode = SetAllowFunctionLiterals(true); | 7038 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7042 SkipExpr(); | 7039 SkipExpr(); |
| 7043 SetAllowFunctionLiterals(saved_mode); | 7040 SetAllowFunctionLiterals(saved_mode); |
| 7044 } | 7041 } |
| 7045 | 7042 |
| 7046 } // namespace dart | 7043 } // namespace dart |
| OLD | NEW |