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

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