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

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

Issue 9716004: Properly recognize closures when setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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/object.cc ('k') | runtime/vm/raw_object.h » ('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/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 3889 matching lines...) Expand 10 before | Expand all | Expand 10 after
3900 } 3900 }
3901 const String& anonymous_function_name = 3901 const String& anonymous_function_name =
3902 String::ZoneHandle(String::NewSymbol("function")); 3902 String::ZoneHandle(String::NewSymbol("function"));
3903 function_name = &anonymous_function_name; 3903 function_name = &anonymous_function_name;
3904 } 3904 }
3905 ASSERT(ident_pos >= 0); 3905 ASSERT(ident_pos >= 0);
3906 3906
3907 if (CurrentToken() != Token::kLPAREN) { 3907 if (CurrentToken() != Token::kLPAREN) {
3908 ErrorMsg("'(' expected"); 3908 ErrorMsg("'(' expected");
3909 } 3909 }
3910 Function& function = Function::ZoneHandle( 3910 intptr_t function_pos = token_index_;
3911 Function::NewClosureFunction(*function_name, 3911
3912 current_function(), 3912 // Check whether we have parsed this closure before, in a previous
3913 token_index_)); 3913 // compilation. If so, reuse the function object, else create a new one
3914 function.set_result_type(result_type); 3914 // and register it in the current class.
3915 Function& function = Function::ZoneHandle();
3916 bool is_new_closure = false;
3917 function = current_class().LookupClosureFunction(function_pos);
3918 if (function.IsNull() || (function.token_index() != function_pos)) {
3919 is_new_closure = true;
3920 function = Function::NewClosureFunction(*function_name,
3921 current_function(),
3922 function_pos);
3923 function.set_result_type(result_type);
3924 current_class().AddClosureFunction(function);
3925 }
3915 3926
3916 // The function type does not need to be determined at compile time, unless 3927 // The function type does not need to be determined at compile time, unless
3917 // the closure is assigned to a function variable and type checks are enabled. 3928 // the closure is assigned to a function variable and type checks are enabled.
3918 // At run time, the function type is derived from the signature class of the 3929 // At run time, the function type is derived from the signature class of the
3919 // closure function and from the type arguments of the instantiator. 3930 // closure function and from the type arguments of the instantiator.
3920 3931
3921 LocalVariable* function_variable = NULL; 3932 LocalVariable* function_variable = NULL;
3922 Type& function_type = Type::ZoneHandle(); 3933 Type& function_type = Type::ZoneHandle();
3923 if (variable_name != NULL) { 3934 if (variable_name != NULL) {
3924 // Since the function type depends on the signature of the closure function, 3935 // Since the function type depends on the signature of the closure function,
(...skipping 18 matching lines...) Expand all
3943 if (!current_block_->scope->AddVariable(function_variable)) { 3954 if (!current_block_->scope->AddVariable(function_variable)) {
3944 ErrorMsg(ident_pos, "identifier '%s' already defined", 3955 ErrorMsg(ident_pos, "identifier '%s' already defined",
3945 function_variable->name().ToCString()); 3956 function_variable->name().ToCString());
3946 } 3957 }
3947 } 3958 }
3948 3959
3949 // Parse the local function. 3960 // Parse the local function.
3950 Array& default_parameter_values = Array::Handle(); 3961 Array& default_parameter_values = Array::Handle();
3951 SequenceNode* statements = Parser::ParseFunc(function, 3962 SequenceNode* statements = Parser::ParseFunc(function,
3952 default_parameter_values); 3963 default_parameter_values);
3964 ASSERT(is_new_closure || (function.end_token_index() == token_index_));
3965 function.set_end_token_index(token_index_);
3953 3966
3954 // Now that the local function has formal parameters, lookup the signature 3967 // Now that the local function has formal parameters, lookup the signature
3955 // class in the current library (but not in its imports) and only create a new 3968 // class in the current library (but not in its imports) and only create a new
3956 // canonical signature class if it does not exist yet. 3969 // canonical signature class if it does not exist yet.
3957 const String& signature = String::Handle(function.Signature()); 3970 const String& signature = String::Handle(function.Signature());
3958 Class& signature_class = Class::ZoneHandle( 3971 Class& signature_class = Class::ZoneHandle(
3959 library_.LookupLocalClass(signature)); 3972 library_.LookupLocalClass(signature));
3973
3960 if (signature_class.IsNull()) { 3974 if (signature_class.IsNull()) {
3975 // If we don't have a signature class yet, this must be a closure we
3976 // have not parsed before.
3977 ASSERT(is_new_closure);
3961 signature_class = Class::NewSignatureClass(signature, 3978 signature_class = Class::NewSignatureClass(signature,
3962 function, 3979 function,
3963 script_); 3980 script_);
3964 // Record the function signature class in the current library. 3981 // Record the function signature class in the current library.
3965 library_.AddClass(signature_class); 3982 library_.AddClass(signature_class);
3966 } else { 3983 } else if (is_new_closure) {
3967 function.set_signature_class(signature_class); 3984 function.set_signature_class(signature_class);
3968 } 3985 }
3969 ASSERT(function.signature_class() == signature_class.raw()); 3986 ASSERT(function.signature_class() == signature_class.raw());
3970 // Local functions are not registered in the enclosing class, which is already 3987
3971 // finalized. 3988 // Local functions are registered in the enclosing class, but
3989 // ignored during class finalization. The enclosing class has
3990 // already been finalized.
3972 ASSERT(current_class().is_finalized()); 3991 ASSERT(current_class().is_finalized());
3973 3992
3974 // Make sure that the instantiator is captured. 3993 // Make sure that the instantiator is captured.
3975 if ((signature_class.NumTypeParameters() > 0) && 3994 if ((signature_class.NumTypeParameters() > 0) &&
3976 (current_block_->scope->function_level() > 0)) { 3995 (current_block_->scope->function_level() > 0)) {
3977 CaptureReceiver(); 3996 CaptureReceiver();
3978 } 3997 }
3979 3998
3980 if (variable_name != NULL) { 3999 if (variable_name != NULL) {
3981 // Patch the function type now that the signature is known. 4000 // Patch the function type now that the signature is known.
(...skipping 4224 matching lines...) Expand 10 before | Expand all | Expand 10 after
8206 void Parser::SkipQualIdent() { 8225 void Parser::SkipQualIdent() {
8207 ASSERT(IsIdentifier()); 8226 ASSERT(IsIdentifier());
8208 ConsumeToken(); 8227 ConsumeToken();
8209 if (CurrentToken() == Token::kPERIOD) { 8228 if (CurrentToken() == Token::kPERIOD) {
8210 ConsumeToken(); // Consume the kPERIOD token. 8229 ConsumeToken(); // Consume the kPERIOD token.
8211 ExpectIdentifier("identifier expected after '.'"); 8230 ExpectIdentifier("identifier expected after '.'");
8212 } 8231 }
8213 } 8232 }
8214 8233
8215 } // namespace dart 8234 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698