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 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 // Record the function signature class in the current library, unless | 1885 // Record the function signature class in the current library, unless |
1886 // we are currently skipping a formal parameter list, in which case | 1886 // we are currently skipping a formal parameter list, in which case |
1887 // the signature class could remain unfinalized. | 1887 // the signature class could remain unfinalized. |
1888 if (!params->skipped) { | 1888 if (!params->skipped) { |
1889 library_.AddClass(signature_class); | 1889 library_.AddClass(signature_class); |
1890 } | 1890 } |
1891 } else { | 1891 } else { |
1892 signature_function.set_signature_class(signature_class); | 1892 signature_function.set_signature_class(signature_class); |
1893 } | 1893 } |
1894 ASSERT(signature_function.signature_class() == signature_class.raw()); | 1894 ASSERT(signature_function.signature_class() == signature_class.raw()); |
1895 Type& signature_type = | 1895 if (!is_top_level_) { |
| 1896 // Finalize types in signature class here, so that the |
| 1897 // signature type is not computed twice. |
| 1898 ClassFinalizer::FinalizeTypesInClass(signature_class); |
| 1899 } |
| 1900 const Type& signature_type = |
1896 Type::ZoneHandle(Z, signature_class.SignatureType()); | 1901 Type::ZoneHandle(Z, signature_class.SignatureType()); |
1897 if (!is_top_level_ && !signature_type.IsFinalized()) { | 1902 ASSERT(is_top_level_ || signature_type.IsFinalized()); |
1898 signature_type ^= ClassFinalizer::FinalizeType( | |
1899 signature_class, signature_type, ClassFinalizer::kCanonicalize); | |
1900 } | |
1901 // A signature type itself cannot be malformed or malbounded, only its | 1903 // A signature type itself cannot be malformed or malbounded, only its |
1902 // signature function's result type or parameter types may be. | 1904 // signature function's result type or parameter types may be. |
1903 ASSERT(!signature_type.IsMalformed()); | 1905 ASSERT(!signature_type.IsMalformed()); |
1904 ASSERT(!signature_type.IsMalbounded()); | 1906 ASSERT(!signature_type.IsMalbounded()); |
1905 // The type of the parameter is now the signature type. | 1907 // The type of the parameter is now the signature type. |
1906 parameter.type = &signature_type; | 1908 parameter.type = &signature_type; |
1907 } | 1909 } |
1908 } | 1910 } |
1909 | 1911 |
1910 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { | 1912 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { |
(...skipping 4647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6558 AddFormalParamsToFunction(&closure_params, body); | 6560 AddFormalParamsToFunction(&closure_params, body); |
6559 | 6561 |
6560 // Create and set the signature class of the closure. | 6562 // Create and set the signature class of the closure. |
6561 const String& sig = String::Handle(Z, body.Signature()); | 6563 const String& sig = String::Handle(Z, body.Signature()); |
6562 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); | 6564 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); |
6563 if (sig_cls.IsNull()) { | 6565 if (sig_cls.IsNull()) { |
6564 sig_cls = Class::NewSignatureClass(sig, body, script_, body.token_pos()); | 6566 sig_cls = Class::NewSignatureClass(sig, body, script_, body.token_pos()); |
6565 library_.AddClass(sig_cls); | 6567 library_.AddClass(sig_cls); |
6566 } | 6568 } |
6567 body.set_signature_class(sig_cls); | 6569 body.set_signature_class(sig_cls); |
| 6570 // Finalize types in signature class here, so that the |
| 6571 // signature type is not computed twice. |
| 6572 ClassFinalizer::FinalizeTypesInClass(sig_cls); |
6568 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); | 6573 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); |
6569 if (!sig_type.IsFinalized()) { | 6574 ASSERT(sig_type.IsFinalized()); |
6570 ClassFinalizer::FinalizeType( | |
6571 sig_cls, sig_type, ClassFinalizer::kCanonicalize); | |
6572 } | |
6573 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); | 6575 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); |
6574 ASSERT(body.NumParameters() == closure_params.parameters->length()); | 6576 ASSERT(body.NumParameters() == closure_params.parameters->length()); |
6575 } | 6577 } |
6576 | 6578 |
6577 OpenFunctionBlock(body); | 6579 OpenFunctionBlock(body); |
6578 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6580 AddFormalParamsToScope(&closure_params, current_block_->scope); |
6579 OpenBlock(); | 6581 OpenBlock(); |
6580 async_temp_scope_ = current_block_->scope; | 6582 async_temp_scope_ = current_block_->scope; |
6581 return body.raw(); | 6583 return body.raw(); |
6582 } | 6584 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6698 | 6700 |
6699 // Create and set the signature class of the closure. | 6701 // Create and set the signature class of the closure. |
6700 const String& sig = String::Handle(Z, closure.Signature()); | 6702 const String& sig = String::Handle(Z, closure.Signature()); |
6701 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); | 6703 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); |
6702 if (sig_cls.IsNull()) { | 6704 if (sig_cls.IsNull()) { |
6703 sig_cls = | 6705 sig_cls = |
6704 Class::NewSignatureClass(sig, closure, script_, closure.token_pos()); | 6706 Class::NewSignatureClass(sig, closure, script_, closure.token_pos()); |
6705 library_.AddClass(sig_cls); | 6707 library_.AddClass(sig_cls); |
6706 } | 6708 } |
6707 closure.set_signature_class(sig_cls); | 6709 closure.set_signature_class(sig_cls); |
| 6710 // Finalize types in signature class here, so that the |
| 6711 // signature type is not computed twice. |
| 6712 ClassFinalizer::FinalizeTypesInClass(sig_cls); |
6708 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); | 6713 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); |
6709 if (!sig_type.IsFinalized()) { | 6714 ASSERT(sig_type.IsFinalized()); |
6710 ClassFinalizer::FinalizeType( | |
6711 sig_cls, sig_type, ClassFinalizer::kCanonicalize); | |
6712 } | |
6713 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 6715 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
6714 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 6716 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
6715 } | 6717 } |
6716 OpenFunctionBlock(closure); | 6718 OpenFunctionBlock(closure); |
6717 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6719 AddFormalParamsToScope(&closure_params, current_block_->scope); |
6718 OpenBlock(); | 6720 OpenBlock(); |
6719 async_temp_scope_ = current_block_->scope; | 6721 async_temp_scope_ = current_block_->scope; |
6720 return closure.raw(); | 6722 return closure.raw(); |
6721 } | 6723 } |
6722 | 6724 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6839 | 6841 |
6840 // Create and set the signature class of the closure. | 6842 // Create and set the signature class of the closure. |
6841 const String& sig = String::Handle(Z, closure.Signature()); | 6843 const String& sig = String::Handle(Z, closure.Signature()); |
6842 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); | 6844 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); |
6843 if (sig_cls.IsNull()) { | 6845 if (sig_cls.IsNull()) { |
6844 sig_cls = | 6846 sig_cls = |
6845 Class::NewSignatureClass(sig, closure, script_, closure.token_pos()); | 6847 Class::NewSignatureClass(sig, closure, script_, closure.token_pos()); |
6846 library_.AddClass(sig_cls); | 6848 library_.AddClass(sig_cls); |
6847 } | 6849 } |
6848 closure.set_signature_class(sig_cls); | 6850 closure.set_signature_class(sig_cls); |
| 6851 // Finalize types in signature class here, so that the |
| 6852 // signature type is not computed twice. |
| 6853 ClassFinalizer::FinalizeTypesInClass(sig_cls); |
6849 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); | 6854 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); |
6850 if (!sig_type.IsFinalized()) { | 6855 ASSERT(sig_type.IsFinalized()); |
6851 ClassFinalizer::FinalizeType( | |
6852 sig_cls, sig_type, ClassFinalizer::kCanonicalize); | |
6853 } | |
6854 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 6856 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
6855 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 6857 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
6856 } | 6858 } |
6857 | 6859 |
6858 OpenFunctionBlock(closure); | 6860 OpenFunctionBlock(closure); |
6859 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6861 AddFormalParamsToScope(&closure_params, current_block_->scope); |
6860 OpenBlock(); | 6862 OpenBlock(); |
6861 async_temp_scope_ = current_block_->scope; | 6863 async_temp_scope_ = current_block_->scope; |
6862 return closure.raw(); | 6864 return closure.raw(); |
6863 } | 6865 } |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7704 // ignored during class finalization. The enclosing class has | 7706 // ignored during class finalization. The enclosing class has |
7705 // already been finalized. | 7707 // already been finalized. |
7706 ASSERT(current_class().is_finalized()); | 7708 ASSERT(current_class().is_finalized()); |
7707 | 7709 |
7708 // Make sure that the instantiator is captured. | 7710 // Make sure that the instantiator is captured. |
7709 if ((signature_class.NumTypeParameters() > 0) && | 7711 if ((signature_class.NumTypeParameters() > 0) && |
7710 (current_block_->scope->function_level() > 0)) { | 7712 (current_block_->scope->function_level() > 0)) { |
7711 CaptureInstantiator(); | 7713 CaptureInstantiator(); |
7712 } | 7714 } |
7713 | 7715 |
7714 // Since the signature type is cached by the signature class, it may have | 7716 // Finalize types in signature class here, so that the |
7715 // been finalized already. | 7717 // signature type is not computed twice. |
7716 Type& signature_type = | 7718 ClassFinalizer::FinalizeTypesInClass(signature_class); |
7717 Type::Handle(Z, signature_class.SignatureType()); | 7719 const Type& signature_type = Type::Handle(Z, signature_class.SignatureType()); |
7718 TypeArguments& signature_type_arguments = | 7720 ASSERT(signature_type.IsFinalized()); |
7719 TypeArguments::Handle(Z, signature_type.arguments()); | |
7720 | |
7721 if (!signature_type.IsFinalized()) { | |
7722 signature_type ^= ClassFinalizer::FinalizeType( | |
7723 signature_class, signature_type, ClassFinalizer::kCanonicalize); | |
7724 | |
7725 // The call to ClassFinalizer::FinalizeType may have | |
7726 // extended the vector of type arguments. | |
7727 signature_type_arguments = signature_type.arguments(); | |
7728 ASSERT(signature_type_arguments.IsNull() || | |
7729 (signature_type_arguments.Length() == | |
7730 signature_class.NumTypeArguments())); | |
7731 | |
7732 // The signature_class should not have changed. | |
7733 ASSERT(signature_type.type_class() == signature_class.raw()); | |
7734 } | |
7735 | 7721 |
7736 // A signature type itself cannot be malformed or malbounded, only its | 7722 // A signature type itself cannot be malformed or malbounded, only its |
7737 // signature function's result type or parameter types may be. | 7723 // signature function's result type or parameter types may be. |
7738 ASSERT(!signature_type.IsMalformed()); | 7724 ASSERT(!signature_type.IsMalformed()); |
7739 ASSERT(!signature_type.IsMalbounded()); | 7725 ASSERT(!signature_type.IsMalbounded()); |
7740 | 7726 |
7741 if (variable_name != NULL) { | 7727 if (variable_name != NULL) { |
7742 // Patch the function type of the variable now that the signature is known. | 7728 // Patch the function type of the variable now that the signature is known. |
7743 function_type.set_type_class(signature_class); | 7729 function_type.set_type_class(signature_class); |
7744 function_type.set_arguments(signature_type_arguments); | 7730 function_type.set_arguments( |
| 7731 TypeArguments::Handle(Z, signature_type.arguments())); |
7745 | 7732 |
7746 // The function type was initially marked as instantiated, but it may | 7733 // The function type was initially marked as instantiated, but it may |
7747 // actually be uninstantiated. | 7734 // actually be uninstantiated. |
7748 function_type.ResetIsFinalized(); | 7735 function_type.ResetIsFinalized(); |
7749 | 7736 |
7750 // The function variable type should have been patched above. | 7737 // The function variable type should have been patched above. |
7751 ASSERT((function_variable == NULL) || | 7738 ASSERT((function_variable == NULL) || |
7752 (function_variable->type().raw() == function_type.raw())); | 7739 (function_variable->type().raw() == function_type.raw())); |
7753 } | 7740 } |
7754 | 7741 |
(...skipping 4100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11855 | 11842 |
11856 const AbstractType* Parser::ReceiverType(const Class& cls) { | 11843 const AbstractType* Parser::ReceiverType(const Class& cls) { |
11857 ASSERT(!cls.IsNull()); | 11844 ASSERT(!cls.IsNull()); |
11858 Type& type = Type::ZoneHandle(Z, cls.CanonicalType()); | 11845 Type& type = Type::ZoneHandle(Z, cls.CanonicalType()); |
11859 if (!type.IsNull()) { | 11846 if (!type.IsNull()) { |
11860 return &type; | 11847 return &type; |
11861 } | 11848 } |
11862 if (cls.IsSignatureClass()) { | 11849 if (cls.IsSignatureClass()) { |
11863 type = cls.SignatureType(); | 11850 type = cls.SignatureType(); |
11864 } else { | 11851 } else { |
11865 const TypeArguments& type_arguments = TypeArguments::Handle(Z, | 11852 type = Type::New(cls, |
11866 (cls.NumTypeParameters() > 0) ? | 11853 TypeArguments::Handle(Z, cls.type_parameters()), cls.token_pos()); |
11867 cls.type_parameters() : TypeArguments::null()); | |
11868 type = Type::New(cls, type_arguments, cls.token_pos()); | |
11869 } | 11854 } |
11870 if (cls.is_type_finalized()) { | 11855 if (cls.is_type_finalized()) { |
11871 type ^= ClassFinalizer::FinalizeType( | 11856 type ^= ClassFinalizer::FinalizeType( |
11872 cls, type, ClassFinalizer::kCanonicalizeWellFormed); | 11857 cls, type, ClassFinalizer::kCanonicalizeWellFormed); |
11873 // Note that the receiver type may now be a malbounded type. | 11858 // Note that the receiver type may now be a malbounded type. |
11874 cls.SetCanonicalType(type); | 11859 cls.SetCanonicalType(type); |
11875 } | 11860 } |
11876 return &type; | 11861 return &type; |
11877 } | 11862 } |
11878 | 11863 |
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13017 AddFormalParamsToFunction(¶ms, closure); | 13002 AddFormalParamsToFunction(¶ms, closure); |
13018 | 13003 |
13019 // Create and set the signature class of the closure. | 13004 // Create and set the signature class of the closure. |
13020 const String& sig = String::Handle(Z, closure.Signature()); | 13005 const String& sig = String::Handle(Z, closure.Signature()); |
13021 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); | 13006 Class& sig_cls = Class::Handle(Z, library_.LookupLocalClass(sig)); |
13022 if (sig_cls.IsNull()) { | 13007 if (sig_cls.IsNull()) { |
13023 sig_cls = Class::NewSignatureClass(sig, closure, script_, token_pos); | 13008 sig_cls = Class::NewSignatureClass(sig, closure, script_, token_pos); |
13024 library_.AddClass(sig_cls); | 13009 library_.AddClass(sig_cls); |
13025 } | 13010 } |
13026 closure.set_signature_class(sig_cls); | 13011 closure.set_signature_class(sig_cls); |
| 13012 // Finalize types in signature class here, so that the |
| 13013 // signature type is not computed twice. |
| 13014 ClassFinalizer::FinalizeTypesInClass(sig_cls); |
13027 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); | 13015 const Type& sig_type = Type::Handle(Z, sig_cls.SignatureType()); |
13028 if (!sig_type.IsFinalized()) { | 13016 ASSERT(sig_type.IsFinalized()); |
13029 // Finalization would be premature when top-level parsing. | 13017 // Finalization would be premature when top-level parsing. |
13030 ASSERT(!is_top_level_); | 13018 ASSERT(!is_top_level_); |
13031 ClassFinalizer::FinalizeType(sig_cls, | |
13032 sig_type, | |
13033 ClassFinalizer::kCanonicalize); | |
13034 } | |
13035 return closure.raw(); | 13019 return closure.raw(); |
13036 } | 13020 } |
13037 | 13021 |
13038 | 13022 |
13039 static String& BuildConstructorName(const String& type_class_name, | 13023 static String& BuildConstructorName(const String& type_class_name, |
13040 const String* named_constructor) { | 13024 const String* named_constructor) { |
13041 // By convention, the static function implementing a named constructor 'C' | 13025 // By convention, the static function implementing a named constructor 'C' |
13042 // for class 'A' is labeled 'A.C', and the static function implementing the | 13026 // for class 'A' is labeled 'A.C', and the static function implementing the |
13043 // unnamed constructor for class 'A' is labeled 'A.'. | 13027 // unnamed constructor for class 'A' is labeled 'A.'. |
13044 // This convention prevents users from explicitly calling constructors. | 13028 // This convention prevents users from explicitly calling constructors. |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14189 void Parser::SkipQualIdent() { | 14173 void Parser::SkipQualIdent() { |
14190 ASSERT(IsIdentifier()); | 14174 ASSERT(IsIdentifier()); |
14191 ConsumeToken(); | 14175 ConsumeToken(); |
14192 if (CurrentToken() == Token::kPERIOD) { | 14176 if (CurrentToken() == Token::kPERIOD) { |
14193 ConsumeToken(); // Consume the kPERIOD token. | 14177 ConsumeToken(); // Consume the kPERIOD token. |
14194 ExpectIdentifier("identifier expected after '.'"); | 14178 ExpectIdentifier("identifier expected after '.'"); |
14195 } | 14179 } |
14196 } | 14180 } |
14197 | 14181 |
14198 } // namespace dart | 14182 } // namespace dart |
OLD | NEW |