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

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

Issue 8372041: Canonicalize types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month 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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 if (signature_class.IsNull()) { 871 if (signature_class.IsNull()) {
872 signature_class = Class::NewSignatureClass(signature, 872 signature_class = Class::NewSignatureClass(signature,
873 signature_function, 873 signature_function,
874 script_); 874 script_);
875 // Record the function signature class in the current library. 875 // Record the function signature class in the current library.
876 library_.AddClass(signature_class); 876 library_.AddClass(signature_class);
877 } else { 877 } else {
878 signature_function.set_signature_class(signature_class); 878 signature_function.set_signature_class(signature_class);
879 } 879 }
880 ASSERT(signature_function.signature_class() == signature_class.raw()); 880 ASSERT(signature_function.signature_class() == signature_class.raw());
881 // The type of the parameter is now the signature type. 881 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType());
882 parameter.type = &Type::ZoneHandle(signature_class.SignatureType()); 882 if (!is_top_level_ && !signature_type.IsFinalized()) {
883 if (!is_top_level_ && !parameter.type->IsFinalized()) { 883 String& errmsg = String::Handle();
884 const String& errmsg = String::Handle( 884 signature_type =
885 ClassFinalizer::FinalizeTypeWhileParsing(*parameter.type)); 885 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, errmsg);
886 if (!errmsg.IsNull()) { 886 if (!errmsg.IsNull()) {
887 ErrorMsg(errmsg.ToCString()); 887 ErrorMsg(errmsg.ToCString());
888 } 888 }
889 } 889 }
890 // The type of the parameter is now the signature type.
891 parameter.type = &signature_type;
890 } 892 }
891 } 893 }
892 894
893 if (CurrentToken() == Token::kASSIGN) { 895 if (CurrentToken() == Token::kASSIGN) {
894 if (!params->has_named_optional_parameters || 896 if (!params->has_named_optional_parameters ||
895 !allow_explicit_default_value) { 897 !allow_explicit_default_value) {
896 ErrorMsg("parameter must not specify a default value"); 898 ErrorMsg("parameter must not specify a default value");
897 } 899 }
898 ConsumeToken(); 900 ConsumeToken();
899 params->num_optional_parameters++; 901 params->num_optional_parameters++;
(...skipping 2537 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 // Make sure that the instantiator is captured. 3439 // Make sure that the instantiator is captured.
3438 if ((signature_class.NumTypeParameters() > 0) && 3440 if ((signature_class.NumTypeParameters() > 0) &&
3439 (current_block_->scope->function_level() > 0)) { 3441 (current_block_->scope->function_level() > 0)) {
3440 CaptureReceiver(); 3442 CaptureReceiver();
3441 } 3443 }
3442 3444
3443 if (variable_name != NULL) { 3445 if (variable_name != NULL) {
3444 // Patch the function type now that the signature is known. 3446 // Patch the function type now that the signature is known.
3445 // We need to create a new type for proper finalization, since the existing 3447 // We need to create a new type for proper finalization, since the existing
3446 // type is already marked as finalized. 3448 // type is already marked as finalized.
3447 const Type& signature_type = Type::Handle(signature_class.SignatureType()); 3449 Type& signature_type = Type::Handle(signature_class.SignatureType());
3448 const TypeArguments& signature_type_arguments = TypeArguments::Handle( 3450 const TypeArguments& signature_type_arguments = TypeArguments::Handle(
3449 signature_type.arguments()); 3451 signature_type.arguments());
3450 3452
3451 // Since the signature type is cached by the signature class, it may have 3453 // Since the signature type is cached by the signature class, it may have
3452 // been finalized already. 3454 // been finalized already.
3453 if (!signature_type.IsFinalized()) { 3455 if (!signature_type.IsFinalized()) {
3454 const String& errmsg = String::Handle( 3456 String& errmsg = String::Handle();
3455 ClassFinalizer::FinalizeTypeWhileParsing(signature_type)); 3457 signature_type =
3458 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, errmsg);
3456 if (!errmsg.IsNull()) { 3459 if (!errmsg.IsNull()) {
3457 ErrorMsg(errmsg.ToCString()); 3460 ErrorMsg(errmsg.ToCString());
3458 } 3461 }
3459 // The call to ClassFinalizer::FinalizeTypeWhileParsing may have extended 3462 // The call to ClassFinalizer::FinalizeTypeWhileParsing may have extended
3460 // the vector of type arguments. 3463 // the vector of type arguments.
3461 ASSERT(signature_type_arguments.IsNull() || 3464 ASSERT(signature_type_arguments.IsNull() ||
3462 (signature_type_arguments.Length() == 3465 (signature_type_arguments.Length() ==
3463 signature_class.NumTypeArguments())); 3466 signature_class.NumTypeArguments()));
3464 // The signature_class should not have changed. 3467 // The signature_class should not have changed.
3465 ASSERT(signature_type.type_class() == signature_class.raw()); 3468 ASSERT(signature_type.type_class() == signature_class.raw());
(...skipping 2653 matching lines...) Expand 10 before | Expand all | Expand 10 after
6119 String::Handle(type_parameter.Name()).ToCString()); 6122 String::Handle(type_parameter.Name()).ToCString());
6120 } 6123 }
6121 return type_parameter.raw(); 6124 return type_parameter.raw();
6122 } 6125 }
6123 } 6126 }
6124 // Try to resolve the type class. 6127 // Try to resolve the type class.
6125 type_class = LookupTypeClass(type_name, type_resolution); 6128 type_class = LookupTypeClass(type_name, type_resolution);
6126 } 6129 }
6127 TypeArguments& type_arguments = 6130 TypeArguments& type_arguments =
6128 TypeArguments::Handle(ParseTypeArguments(type_resolution)); 6131 TypeArguments::Handle(ParseTypeArguments(type_resolution));
6129 const Type& type = Type::Handle( 6132 Type& type = Type::Handle(
6130 Type::NewParameterizedType(type_class, type_arguments)); 6133 Type::NewParameterizedType(type_class, type_arguments));
6131 if (type_resolution == kMustResolve) { 6134 if (type_resolution == kMustResolve) {
6132 ASSERT(type_class.IsClass()); // Must be resolved. 6135 ASSERT(type_class.IsClass()); // Must be resolved.
6133 const String& errmsg = String::Handle( 6136 String& errmsg = String::Handle();
6134 ClassFinalizer::FinalizeTypeWhileParsing(type)); 6137 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, errmsg);
6135 if (!errmsg.IsNull()) { 6138 if (!errmsg.IsNull()) {
6136 ErrorMsg(errmsg.ToCString()); 6139 ErrorMsg(errmsg.ToCString());
6137 } 6140 }
6138 } 6141 }
6139 return type.raw(); 6142 return type.raw();
6140 } 6143 }
6141 6144
6142 6145
6143 // Parse "[" [ expr { "," expr } ["," ] "]". 6146 // Parse "[" [ expr { "," expr } ["," ] "]".
6144 // Note: if the array literal is empty and the brackets have no whitespace 6147 // Note: if the array literal is empty and the brackets have no whitespace
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
6450 CheckTypeParameterReference(type_name.ident_pos, *type_name.ident); 6453 CheckTypeParameterReference(type_name.ident_pos, *type_name.ident);
6451 ErrorMsg(type_pos, "type parameter '%s' cannot be instantiated", 6454 ErrorMsg(type_pos, "type parameter '%s' cannot be instantiated",
6452 String::Handle(type_parameter.Name()).ToCString()); 6455 String::Handle(type_parameter.Name()).ToCString());
6453 } 6456 }
6454 type_class ^= LookupTypeClass(type_name, kMustResolve); 6457 type_class ^= LookupTypeClass(type_name, kMustResolve);
6455 type_class_name = type_class.Name(); 6458 type_class_name = type_class.Name();
6456 // Type arguments are not allowed after the optional constructor name. 6459 // Type arguments are not allowed after the optional constructor name.
6457 if (named_constructor == NULL) { 6460 if (named_constructor == NULL) {
6458 type_arguments = ParseTypeArguments(kMustResolve); 6461 type_arguments = ParseTypeArguments(kMustResolve);
6459 type = Type::NewParameterizedType(type_class, type_arguments); 6462 type = Type::NewParameterizedType(type_class, type_arguments);
6460 const String& errmsg = String::Handle( 6463 String& errmsg = String::Handle();
6461 ClassFinalizer::FinalizeTypeWhileParsing(type)); 6464 type = ClassFinalizer::FinalizeAndCanonicalizeType(type, errmsg);
6462 if (!errmsg.IsNull()) { 6465 if (!errmsg.IsNull()) {
6463 ErrorMsg(errmsg.ToCString()); 6466 ErrorMsg(errmsg.ToCString());
6464 } 6467 }
6465 // The type argument vector may have been expanded with the type arguments 6468 // The type argument vector may have been expanded with the type arguments
6466 // of the super type when finalizing the type. 6469 // of the super type when finalizing the type.
6467 type_arguments = type.arguments(); 6470 type_arguments = type.arguments();
6468 } 6471 }
6469 if ((named_constructor == NULL) && (CurrentToken() == Token::kPERIOD)) { 6472 if ((named_constructor == NULL) && (CurrentToken() == Token::kPERIOD)) {
6470 ConsumeToken(); 6473 ConsumeToken();
6471 named_constructor = ExpectIdentifier("name of constructor expected"); 6474 named_constructor = ExpectIdentifier("name of constructor expected");
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
7018 } 7021 }
7019 7022
7020 7023
7021 void Parser::SkipNestedExpr() { 7024 void Parser::SkipNestedExpr() {
7022 const bool saved_mode = SetAllowFunctionLiterals(true); 7025 const bool saved_mode = SetAllowFunctionLiterals(true);
7023 SkipExpr(); 7026 SkipExpr();
7024 SetAllowFunctionLiterals(saved_mode); 7027 SetAllowFunctionLiterals(saved_mode);
7025 } 7028 }
7026 7029
7027 } // namespace dart 7030 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « 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