| 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 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 const Function& signature_function = Function::Handle( | 842 const Function& signature_function = Function::Handle( |
| 843 Function::New(*parameter.name, | 843 Function::New(*parameter.name, |
| 844 RawFunction::kSignatureFunction, | 844 RawFunction::kSignatureFunction, |
| 845 /* is_static = */ false, | 845 /* is_static = */ false, |
| 846 /* is_const = */ false, | 846 /* is_const = */ false, |
| 847 parameter.name_pos)); | 847 parameter.name_pos)); |
| 848 signature_function.set_owner(current_class()); | 848 signature_function.set_owner(current_class()); |
| 849 signature_function.set_result_type(result_type); | 849 signature_function.set_result_type(result_type); |
| 850 AddFormalParamsToFunction(&func_params, signature_function); | 850 AddFormalParamsToFunction(&func_params, signature_function); |
| 851 const String& signature = String::Handle(signature_function.Signature()); | 851 const String& signature = String::Handle(signature_function.Signature()); |
| 852 // Lookup the class named signature and only create a new class if it does | 852 // Lookup the signature class, i.e. the class whose name is the signature. |
| 853 // not exist yet. | 853 // We only lookup in the current library, but not in its imports, and only |
| 854 Class& signature_class = Class::ZoneHandle(LookupClass(signature)); | 854 // create a new canonical signature class if it does not exist yet. |
| 855 Class& signature_class = Class::ZoneHandle( |
| 856 library_.LookupLocalClass(signature)); |
| 855 if (signature_class.IsNull()) { | 857 if (signature_class.IsNull()) { |
| 856 signature_class = Class::NewSignatureClass(signature, | 858 signature_class = Class::NewSignatureClass(signature, |
| 857 signature_function, | 859 signature_function, |
| 858 script_, | 860 script_); |
| 859 parameter.name_pos); | 861 // Record the function signature class in the current library. |
| 860 // Record the function signature class in the library. | |
| 861 library_.AddClass(signature_class); | 862 library_.AddClass(signature_class); |
| 863 } else { |
| 864 signature_function.set_signature_class(signature_class); |
| 862 } | 865 } |
| 863 ASSERT(!Function::Handle(signature_class.signature_function()).IsNull()); | 866 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 864 ASSERT(Class::Handle(signature_function.signature_class()).IsNull()); | |
| 865 signature_function.set_signature_class(signature_class); | |
| 866 | |
| 867 // The type of the parameter is now the signature type. | 867 // The type of the parameter is now the signature type. |
| 868 parameter.type = &Type::ZoneHandle(signature_class.SignatureType()); | 868 parameter.type = &Type::ZoneHandle(signature_class.SignatureType()); |
| 869 if (!is_top_level_ && !parameter.type->IsFinalized()) { | 869 if (!is_top_level_ && !parameter.type->IsFinalized()) { |
| 870 const String& errmsg = String::Handle( | 870 const String& errmsg = String::Handle( |
| 871 ClassFinalizer::FinalizeTypeWhileParsing(*parameter.type)); | 871 ClassFinalizer::FinalizeTypeWhileParsing(*parameter.type)); |
| 872 if (!errmsg.IsNull()) { | 872 if (!errmsg.IsNull()) { |
| 873 ErrorMsg(errmsg.ToCString()); | 873 ErrorMsg(errmsg.ToCString()); |
| 874 } | 874 } |
| 875 } | 875 } |
| 876 } | 876 } |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 /* is_const = */ false, | 2412 /* is_const = */ false, |
| 2413 alias_name_pos)); | 2413 alias_name_pos)); |
| 2414 signature_function.set_owner(alias_owner); | 2414 signature_function.set_owner(alias_owner); |
| 2415 signature_function.set_result_type(result_type); | 2415 signature_function.set_result_type(result_type); |
| 2416 AddFormalParamsToFunction(&func_params, signature_function); | 2416 AddFormalParamsToFunction(&func_params, signature_function); |
| 2417 const String& signature = String::Handle(signature_function.Signature()); | 2417 const String& signature = String::Handle(signature_function.Signature()); |
| 2418 if (FLAG_trace_parser) { | 2418 if (FLAG_trace_parser) { |
| 2419 OS::Print("TopLevel parsing function type alias '%s'\n", | 2419 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 2420 signature.ToCString()); | 2420 signature.ToCString()); |
| 2421 } | 2421 } |
| 2422 // Lookup the class by its signature and only create a new canonical signature | 2422 // Lookup the signature class, i.e. the class whose name is the signature. |
| 2423 // class if it does not exist yet. | 2423 // We only lookup in the current library, but not in its imports, and only |
| 2424 Class& signature_class = Class::ZoneHandle(LookupClass(signature)); | 2424 // create a new canonical signature class if it does not exist yet. |
| 2425 Class& signature_class = Class::ZoneHandle( |
| 2426 library_.LookupLocalClass(signature)); |
| 2425 if (signature_class.IsNull()) { | 2427 if (signature_class.IsNull()) { |
| 2426 signature_class = Class::NewSignatureClass(signature, | 2428 signature_class = Class::NewSignatureClass(signature, |
| 2427 signature_function, | 2429 signature_function, |
| 2428 script_, | 2430 script_); |
| 2429 alias_name_pos); | 2431 // Record the function signature class in the current library. |
| 2430 // Record the function signature class in the library. | |
| 2431 library_.AddClass(signature_class); | 2432 library_.AddClass(signature_class); |
| 2432 ASSERT(Class::Handle(signature_function.signature_class()).IsNull()); | |
| 2433 signature_function.set_signature_class(signature_class); | |
| 2434 } else { | 2433 } else { |
| 2435 // Forget the just created function type desc and use the existing one. | 2434 // Forget the just created signature function and use the existing one. |
| 2436 signature_function = signature_class.signature_function(); | 2435 signature_function = signature_class.signature_function(); |
| 2437 ASSERT(signature_function.signature_class() == signature_class.raw()); | |
| 2438 } | 2436 } |
| 2437 ASSERT(signature_function.signature_class() == signature_class.raw()); |
| 2439 // Lookup the class by its alias name and report an error if it exists. | 2438 // Lookup the class by its alias name and report an error if it exists. |
| 2440 Class& function_type_alias = Class::ZoneHandle(LookupClass(*alias_name)); | 2439 Class& function_type_alias = Class::ZoneHandle(LookupClass(*alias_name)); |
| 2441 if (function_type_alias.IsNull()) { | 2440 if (function_type_alias.IsNull()) { |
| 2442 // Create the function type alias, but share the signature function of the | 2441 // Create the function type alias, but share the signature function of the |
| 2443 // canonical signature class. | 2442 // canonical signature class. |
| 2444 function_type_alias = Class::NewSignatureClass(*alias_name, | 2443 function_type_alias = Class::NewSignatureClass(*alias_name, |
| 2445 signature_function, | 2444 signature_function, |
| 2446 script_, | 2445 script_); |
| 2447 alias_name_pos); | |
| 2448 library_.AddClass(function_type_alias); | 2446 library_.AddClass(function_type_alias); |
| 2449 } else { | 2447 } else { |
| 2450 const char* format = function_type_alias.is_interface() ? | 2448 const char* format = function_type_alias.is_interface() ? |
| 2451 "'%s' is already defined" : "'%s' is already defined as class"; | 2449 "'%s' is already defined" : "'%s' is already defined as class"; |
| 2452 ErrorMsg(alias_name_pos, format, alias_name->ToCString()); | 2450 ErrorMsg(alias_name_pos, format, alias_name->ToCString()); |
| 2453 } | 2451 } |
| 2454 ExpectSemicolon(); | 2452 ExpectSemicolon(); |
| 2455 classes->Add(&function_type_alias); | 2453 classes->Add(&function_type_alias); |
| 2456 } | 2454 } |
| 2457 | 2455 |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3408 ErrorMsg(ident_pos, "identifier '%s' already defined", | 3406 ErrorMsg(ident_pos, "identifier '%s' already defined", |
| 3409 function_variable->name().ToCString()); | 3407 function_variable->name().ToCString()); |
| 3410 } | 3408 } |
| 3411 } | 3409 } |
| 3412 | 3410 |
| 3413 // Parse the local function. | 3411 // Parse the local function. |
| 3414 Array& default_parameter_values = Array::Handle(); | 3412 Array& default_parameter_values = Array::Handle(); |
| 3415 SequenceNode* statements = Parser::ParseFunc(function, | 3413 SequenceNode* statements = Parser::ParseFunc(function, |
| 3416 default_parameter_values); | 3414 default_parameter_values); |
| 3417 | 3415 |
| 3418 // Now that the local function has formal parameters, lookup or create a new | 3416 // Now that the local function has formal parameters, lookup the signature |
| 3419 // signature class for it. | 3417 // class in the current library (but not in its imports) and only create a new |
| 3418 // canonical signature class if it does not exist yet. |
| 3420 const String& signature = String::Handle(function.Signature()); | 3419 const String& signature = String::Handle(function.Signature()); |
| 3421 Class& signature_class = Class::Handle(LookupClass(signature)); | 3420 Class& signature_class = Class::ZoneHandle( |
| 3421 library_.LookupLocalClass(signature)); |
| 3422 if (signature_class.IsNull()) { | 3422 if (signature_class.IsNull()) { |
| 3423 signature_class = Class::NewSignatureClass(signature, | 3423 signature_class = Class::NewSignatureClass(signature, |
| 3424 function, | 3424 function, |
| 3425 script_, | 3425 script_); |
| 3426 ident_pos); | 3426 // Record the function signature class in the current library. |
| 3427 // Record the function signature class in the library. | |
| 3428 library_.AddClass(signature_class); | 3427 library_.AddClass(signature_class); |
| 3428 } else { |
| 3429 function.set_signature_class(signature_class); |
| 3429 } | 3430 } |
| 3430 ASSERT(!Function::Handle(signature_class.signature_function()).IsNull()); | 3431 ASSERT(function.signature_class() == signature_class.raw()); |
| 3431 ASSERT(Class::Handle(function.signature_class()).IsNull()); | |
| 3432 function.set_signature_class(signature_class); | |
| 3433 | |
| 3434 // Local functions are not registered in the enclosing class, which is already | 3432 // Local functions are not registered in the enclosing class, which is already |
| 3435 // finalized. | 3433 // finalized. |
| 3436 ASSERT(current_class().is_finalized()); | 3434 ASSERT(current_class().is_finalized()); |
| 3437 | 3435 |
| 3438 // Make sure that the instantiator is captured. | 3436 // Make sure that the instantiator is captured. |
| 3439 if ((signature_class.NumTypeParameters() > 0) && | 3437 if ((signature_class.NumTypeParameters() > 0) && |
| 3440 (current_block_->scope->function_level() > 0)) { | 3438 (current_block_->scope->function_level() > 0)) { |
| 3441 CaptureReceiver(); | 3439 CaptureReceiver(); |
| 3442 } | 3440 } |
| 3443 | 3441 |
| (...skipping 3561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7005 } | 7003 } |
| 7006 | 7004 |
| 7007 | 7005 |
| 7008 void Parser::SkipNestedExpr() { | 7006 void Parser::SkipNestedExpr() { |
| 7009 const bool saved_mode = SetAllowFunctionLiterals(true); | 7007 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7010 SkipExpr(); | 7008 SkipExpr(); |
| 7011 SetAllowFunctionLiterals(saved_mode); | 7009 SetAllowFunctionLiterals(saved_mode); |
| 7012 } | 7010 } |
| 7013 | 7011 |
| 7014 } // namespace dart | 7012 } // namespace dart |
| OLD | NEW |