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

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

Issue 8872037: Adjust index of type parameters at finalization time (fix issue 718). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years 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
OLDNEW
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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 script_); 873 script_);
874 // Record the function signature class in the current library. 874 // Record the function signature class in the current library.
875 library_.AddClass(signature_class); 875 library_.AddClass(signature_class);
876 } else { 876 } else {
877 signature_function.set_signature_class(signature_class); 877 signature_function.set_signature_class(signature_class);
878 } 878 }
879 ASSERT(signature_function.signature_class() == signature_class.raw()); 879 ASSERT(signature_function.signature_class() == signature_class.raw());
880 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); 880 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType());
881 if (!is_top_level_ && !signature_type.IsFinalized()) { 881 if (!is_top_level_ && !signature_type.IsFinalized()) {
882 String& errmsg = String::Handle(); 882 String& errmsg = String::Handle();
883 signature_type = 883 signature_type ^=
884 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, 884 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
885 signature_type,
885 &errmsg); 886 &errmsg);
886 if (!errmsg.IsNull()) { 887 if (!errmsg.IsNull()) {
887 ErrorMsg(errmsg.ToCString()); 888 ErrorMsg(errmsg.ToCString());
888 } 889 }
889 } 890 }
890 // The type of the parameter is now the signature type. 891 // The type of the parameter is now the signature type.
891 parameter.type = &signature_type; 892 parameter.type = &signature_type;
892 } 893 }
893 } 894 }
894 895
(...skipping 2852 matching lines...) Expand 10 before | Expand all | Expand 10 after
3747 // We need to create a new type for proper finalization, since the existing 3748 // We need to create a new type for proper finalization, since the existing
3748 // type is already marked as finalized. 3749 // type is already marked as finalized.
3749 Type& signature_type = Type::Handle(signature_class.SignatureType()); 3750 Type& signature_type = Type::Handle(signature_class.SignatureType());
3750 const AbstractTypeArguments& signature_type_arguments = 3751 const AbstractTypeArguments& signature_type_arguments =
3751 AbstractTypeArguments::Handle(signature_type.arguments()); 3752 AbstractTypeArguments::Handle(signature_type.arguments());
3752 3753
3753 // Since the signature type is cached by the signature class, it may have 3754 // Since the signature type is cached by the signature class, it may have
3754 // been finalized already. 3755 // been finalized already.
3755 if (!signature_type.IsFinalized()) { 3756 if (!signature_type.IsFinalized()) {
3756 String& errmsg = String::Handle(); 3757 String& errmsg = String::Handle();
3757 signature_type = 3758 signature_type ^=
3758 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); 3759 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
3760 signature_type,
3761 &errmsg);
3759 if (!errmsg.IsNull()) { 3762 if (!errmsg.IsNull()) {
3760 ErrorMsg(errmsg.ToCString()); 3763 ErrorMsg(errmsg.ToCString());
3761 } 3764 }
3762 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have 3765 // The call to ClassFinalizer::FinalizeAndCanonicalizeType may have
3763 // extended the vector of type arguments. 3766 // extended the vector of type arguments.
3764 ASSERT(signature_type_arguments.IsNull() || 3767 ASSERT(signature_type_arguments.IsNull() ||
3765 (signature_type_arguments.Length() == 3768 (signature_type_arguments.Length() ==
3766 signature_class.NumTypeArguments())); 3769 signature_class.NumTypeArguments()));
3767 // The signature_class should not have changed. 3770 // The signature_class should not have changed.
3768 ASSERT(signature_type.type_class() == signature_class.raw()); 3771 ASSERT(signature_type.type_class() == signature_class.raw());
(...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after
6548 if (CurrentToken() != Token::kIDENT) { 6551 if (CurrentToken() != Token::kIDENT) {
6549 ErrorMsg("type name expected"); 6552 ErrorMsg("type name expected");
6550 } 6553 }
6551 QualIdent type_name; 6554 QualIdent type_name;
6552 const intptr_t type_pos = token_index_; 6555 const intptr_t type_pos = token_index_;
6553 ParseQualIdent(&type_name); 6556 ParseQualIdent(&type_name);
6554 if (type_name.is_local_scope_ident) { 6557 if (type_name.is_local_scope_ident) {
6555 ErrorMsg(type_pos, "using '%s' in this context is invalid", 6558 ErrorMsg(type_pos, "using '%s' in this context is invalid",
6556 type_name.ident->ToCString()); 6559 type_name.ident->ToCString());
6557 } 6560 }
6561 Class& scope_class = Class::Handle();
6558 Object& type_class = Object::Handle(); 6562 Object& type_class = Object::Handle();
6559 if (type_resolution == kDoNotResolve) { 6563 if (type_resolution == kDoNotResolve) {
6560 String& qualifier = String::Handle(); 6564 String& qualifier = String::Handle();
6561 if (type_name.qualifier != NULL) { 6565 if (type_name.qualifier != NULL) {
6562 qualifier ^= type_name.qualifier->raw(); 6566 qualifier ^= type_name.qualifier->raw();
6563 } 6567 }
6564 type_class = UnresolvedClass::New(type_pos, qualifier, *(type_name.ident)); 6568 type_class = UnresolvedClass::New(type_pos, qualifier, *(type_name.ident));
6565 } else { 6569 } else {
6566 const Class& scope_class = Class::Handle(TypeParametersScopeClass()); 6570 scope_class = TypeParametersScopeClass();
6567 if (!scope_class.IsNull()) { 6571 if (!scope_class.IsNull()) {
6568 TypeParameter& type_parameter = TypeParameter::Handle(); 6572 TypeParameter& type_parameter = TypeParameter::Handle();
6569 // Check if qualifier is a type parameter in scope. 6573 // Check if qualifier is a type parameter in scope.
6570 if (type_name.qualifier != NULL) { 6574 if (type_name.qualifier != NULL) {
6571 type_parameter = scope_class.LookupTypeParameter(*type_name.qualifier); 6575 type_parameter = scope_class.LookupTypeParameter(*type_name.qualifier);
6572 if (!type_parameter.IsNull()) { 6576 if (!type_parameter.IsNull()) {
6573 ErrorMsg(type_pos, "type Parameter '%s' cannot be used as qualifier", 6577 ErrorMsg(type_pos, "type Parameter '%s' cannot be used as qualifier",
6574 type_name.qualifier->ToCString()); 6578 type_name.qualifier->ToCString());
6575 } 6579 }
6576 } else { 6580 } else {
6577 // Check if ident is a type parameter in scope. 6581 // Check if ident is a type parameter in scope.
6578 type_parameter = scope_class.LookupTypeParameter(*type_name.ident); 6582 type_parameter = scope_class.LookupTypeParameter(*type_name.ident);
6579 if (!type_parameter.IsNull()) { 6583 if (!type_parameter.IsNull()) {
6580 if (CurrentToken() == Token::kLT) { 6584 if (CurrentToken() == Token::kLT) {
6581 // A type parameter cannot be parameterized. 6585 // A type parameter cannot be parameterized.
6582 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized", 6586 ErrorMsg(type_pos, "type parameter '%s' cannot be parameterized",
6583 String::Handle(type_parameter.Name()).ToCString()); 6587 String::Handle(type_parameter.Name()).ToCString());
6584 } 6588 }
6589 if (type_resolution == kMustResolve) {
6590 String& errmsg = String::Handle();
6591 type_parameter ^=
6592 ClassFinalizer::FinalizeAndCanonicalizeType(scope_class,
6593 type_parameter,
6594 &errmsg);
6595 if (!errmsg.IsNull()) {
6596 ErrorMsg(errmsg.ToCString());
6597 }
6598 }
6585 return type_parameter.raw(); 6599 return type_parameter.raw();
6586 } 6600 }
6587 } 6601 }
6588 } 6602 }
6589 // Try to resolve the type class. 6603 // Try to resolve the type class.
6590 type_class = LookupTypeClass(type_name, type_resolution); 6604 type_class = LookupTypeClass(type_name, type_resolution);
6591 } 6605 }
6592 AbstractTypeArguments& type_arguments = 6606 AbstractTypeArguments& type_arguments =
6593 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution)); 6607 AbstractTypeArguments::Handle(ParseTypeArguments(type_resolution));
6594 Type& type = Type::Handle( 6608 Type& type = Type::Handle(
6595 Type::NewParameterizedType(type_class, type_arguments)); 6609 Type::NewParameterizedType(type_class, type_arguments));
6596 if (type_resolution == kMustResolve) { 6610 if (type_resolution == kMustResolve) {
6597 ASSERT(type_class.IsClass()); // Must be resolved. 6611 ASSERT(type_class.IsClass()); // Must be resolved.
6598 String& errmsg = String::Handle(); 6612 String& errmsg = String::Handle();
6599 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); 6613 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(scope_class,
6614 type,
6615 &errmsg);
6600 if (!errmsg.IsNull()) { 6616 if (!errmsg.IsNull()) {
6601 ErrorMsg(errmsg.ToCString()); 6617 ErrorMsg(errmsg.ToCString());
6602 } 6618 }
6603 } 6619 }
6604 return type.raw(); 6620 return type.raw();
6605 } 6621 }
6606 6622
6607 6623
6608 void Parser::CheckConstructorCallTypeArguments( 6624 void Parser::CheckConstructorCallTypeArguments(
6609 intptr_t pos, Function& constructor, 6625 intptr_t pos, Function& constructor,
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
7140 if (constructor.IsFactory()) { 7156 if (constructor.IsFactory()) {
7141 signature_class = constructor.signature_class(); 7157 signature_class = constructor.signature_class();
7142 } else { 7158 } else {
7143 signature_class = constructor.owner(); 7159 signature_class = constructor.owner();
7144 ASSERT(signature_class.raw() == type_class.raw()); 7160 ASSERT(signature_class.raw() == type_class.raw());
7145 } 7161 }
7146 // TODO(regis): Temporary type should be allocated in new gen heap. 7162 // TODO(regis): Temporary type should be allocated in new gen heap.
7147 Type& type = Type::Handle( 7163 Type& type = Type::Handle(
7148 Type::NewParameterizedType(signature_class, type_arguments)); 7164 Type::NewParameterizedType(signature_class, type_arguments));
7149 String& errmsg = String::Handle(); 7165 String& errmsg = String::Handle();
7150 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, &errmsg); 7166 type ^= ClassFinalizer::FinalizeAndCanonicalizeType(signature_class,
7167 type,
7168 &errmsg);
7151 if (!errmsg.IsNull()) { 7169 if (!errmsg.IsNull()) {
7152 ErrorMsg(errmsg.ToCString()); 7170 ErrorMsg(errmsg.ToCString());
7153 } 7171 }
7154 // The type argument vector may have been expanded with the type arguments 7172 // The type argument vector may have been expanded with the type arguments
7155 // of the super type when finalizing the type. 7173 // of the super type when finalizing the type.
7156 type_arguments = type.arguments(); 7174 type_arguments = type.arguments();
7157 } 7175 }
7158 7176
7159 type_arguments ^= type_arguments.Canonicalize(); 7177 type_arguments ^= type_arguments.Canonicalize();
7160 // Make the constructor call. 7178 // Make the constructor call.
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
7620 } 7638 }
7621 7639
7622 7640
7623 void Parser::SkipNestedExpr() { 7641 void Parser::SkipNestedExpr() {
7624 const bool saved_mode = SetAllowFunctionLiterals(true); 7642 const bool saved_mode = SetAllowFunctionLiterals(true);
7625 SkipExpr(); 7643 SkipExpr();
7626 SetAllowFunctionLiterals(saved_mode); 7644 SetAllowFunctionLiterals(saved_mode);
7627 } 7645 }
7628 7646
7629 } // namespace dart 7647 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698