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

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

Issue 23465004: More cleanup related to malformed and malbounded types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months 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/os_linux.cc ('k') | runtime/vm/raw_object_snapshot.cc » ('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) 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 "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 12 matching lines...) Expand all
23 #include "vm/stack_frame.h" 23 #include "vm/stack_frame.h"
24 #include "vm/symbols.h" 24 #include "vm/symbols.h"
25 25
26 namespace dart { 26 namespace dart {
27 27
28 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); 28 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements.");
29 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); 29 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks.");
30 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); 30 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations.");
31 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); 31 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors.");
32 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); 32 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings.");
33 DECLARE_FLAG(bool, error_on_malformed_type); 33 DECLARE_FLAG(bool, error_on_bad_type);
34 DECLARE_FLAG(bool, throw_on_javascript_int_overflow); 34 DECLARE_FLAG(bool, throw_on_javascript_int_overflow);
35 35
36 static void CheckedModeHandler(bool value) { 36 static void CheckedModeHandler(bool value) {
37 FLAG_enable_asserts = value; 37 FLAG_enable_asserts = value;
38 FLAG_enable_type_checks = value; 38 FLAG_enable_type_checks = value;
39 } 39 }
40 40
41 // --enable-checked-mode and --checked both enable checked mode which is 41 // --enable-checked-mode and --checked both enable checked mode which is
42 // equivalent to setting --enable-asserts and --enable-type-checks. 42 // equivalent to setting --enable-asserts and --enable-type-checks.
43 DEFINE_FLAG_HANDLER(CheckedModeHandler, 43 DEFINE_FLAG_HANDLER(CheckedModeHandler,
(...skipping 8232 matching lines...) Expand 10 before | Expand all | Expand 10 after
8276 if (!scope_class.IsNull()) { 8276 if (!scope_class.IsNull()) {
8277 // First check if the type is a type parameter of the given scope class. 8277 // First check if the type is a type parameter of the given scope class.
8278 const TypeParameter& type_parameter = TypeParameter::Handle( 8278 const TypeParameter& type_parameter = TypeParameter::Handle(
8279 scope_class.LookupTypeParameter(unresolved_class_name)); 8279 scope_class.LookupTypeParameter(unresolved_class_name));
8280 if (!type_parameter.IsNull()) { 8280 if (!type_parameter.IsNull()) {
8281 // A type parameter is considered to be a malformed type when 8281 // A type parameter is considered to be a malformed type when
8282 // referenced by a static member. 8282 // referenced by a static member.
8283 if (ParsingStaticMember()) { 8283 if (ParsingStaticMember()) {
8284 ASSERT(scope_class.raw() == current_class().raw()); 8284 ASSERT(scope_class.raw() == current_class().raw());
8285 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) || 8285 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) ||
8286 FLAG_error_on_malformed_type) { 8286 FLAG_error_on_bad_type) {
8287 *type = ClassFinalizer::NewFinalizedMalformedType( 8287 *type = ClassFinalizer::NewFinalizedMalformedType(
8288 Error::Handle(), // No previous error. 8288 Error::Handle(), // No previous error.
8289 scope_class, 8289 scope_class,
8290 type->token_pos(), 8290 type->token_pos(),
8291 "type parameter '%s' cannot be referenced " 8291 "type parameter '%s' cannot be referenced "
8292 "from static member", 8292 "from static member",
8293 String::Handle(type_parameter.name()).ToCString()); 8293 String::Handle(type_parameter.name()).ToCString());
8294 } else { 8294 } else {
8295 // Map the malformed type to dynamic and ignore type arguments. 8295 // Map the malformed type to dynamic and ignore type arguments.
8296 *type = Type::DynamicType(); 8296 *type = Type::DynamicType();
8297 } 8297 }
8298 return; 8298 return;
8299 } 8299 }
8300 // A type parameter cannot be parameterized, so make the type 8300 // A type parameter cannot be parameterized, so make the type
8301 // malformed if type arguments have previously been parsed. 8301 // malformed if type arguments have previously been parsed.
8302 if (!AbstractTypeArguments::Handle(type->arguments()).IsNull()) { 8302 if (!AbstractTypeArguments::Handle(type->arguments()).IsNull()) {
8303 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) || 8303 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) ||
8304 FLAG_error_on_malformed_type) { 8304 FLAG_error_on_bad_type) {
8305 *type = ClassFinalizer::NewFinalizedMalformedType( 8305 *type = ClassFinalizer::NewFinalizedMalformedType(
8306 Error::Handle(), // No previous error. 8306 Error::Handle(), // No previous error.
8307 scope_class, 8307 scope_class,
8308 type_parameter.token_pos(), 8308 type_parameter.token_pos(),
8309 "type parameter '%s' cannot be parameterized", 8309 "type parameter '%s' cannot be parameterized",
8310 String::Handle(type_parameter.name()).ToCString()); 8310 String::Handle(type_parameter.name()).ToCString());
8311 } else { 8311 } else {
8312 // Map the malformed type to dynamic and ignore type arguments. 8312 // Map the malformed type to dynamic and ignore type arguments.
8313 *type = Type::DynamicType(); 8313 *type = Type::DynamicType();
8314 } 8314 }
8315 return; 8315 return;
8316 } 8316 }
8317 *type = type_parameter.raw(); 8317 *type = type_parameter.raw();
8318 return; 8318 return;
8319 } 8319 }
8320 } 8320 }
8321 // The referenced class may not have been parsed yet. It would be wrong 8321 // The referenced class may not have been parsed yet. It would be wrong
8322 // to resolve it too early to an imported class of the same name. 8322 // to resolve it too early to an imported class of the same name.
8323 if (finalization > ClassFinalizer::kResolveTypeParameters) { 8323 if (finalization > ClassFinalizer::kResolveTypeParameters) {
8324 // Resolve classname in the scope of the current library. 8324 // Resolve classname in the scope of the current library.
8325 Error& error = Error::Handle(); 8325 Error& error = Error::Handle();
8326 resolved_type_class = ResolveClassInCurrentLibraryScope( 8326 resolved_type_class = ResolveClassInCurrentLibraryScope(
8327 unresolved_class.token_pos(), 8327 unresolved_class.token_pos(),
8328 unresolved_class_name, 8328 unresolved_class_name,
8329 &error); 8329 &error);
8330 if (!error.IsNull()) { 8330 if (!error.IsNull()) {
8331 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) || 8331 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) ||
8332 FLAG_error_on_malformed_type) { 8332 FLAG_error_on_bad_type) {
8333 *type = ClassFinalizer::NewFinalizedMalformedType( 8333 *type = ClassFinalizer::NewFinalizedMalformedType(
8334 error, 8334 error,
8335 scope_class, 8335 scope_class,
8336 unresolved_class.token_pos(), 8336 unresolved_class.token_pos(),
8337 "cannot resolve class '%s'", 8337 "cannot resolve class '%s'",
8338 unresolved_class_name.ToCString()); 8338 unresolved_class_name.ToCString());
8339 } else { 8339 } else {
8340 // Map the malformed type to dynamic and ignore type arguments. 8340 // Map the malformed type to dynamic and ignore type arguments.
8341 *type = Type::DynamicType(); 8341 *type = Type::DynamicType();
8342 } 8342 }
8343 return; 8343 return;
8344 } 8344 }
8345 } 8345 }
8346 } else { 8346 } else {
8347 LibraryPrefix& lib_prefix = 8347 LibraryPrefix& lib_prefix =
8348 LibraryPrefix::Handle(unresolved_class.library_prefix()); 8348 LibraryPrefix::Handle(unresolved_class.library_prefix());
8349 // Resolve class name in the scope of the library prefix. 8349 // Resolve class name in the scope of the library prefix.
8350 Error& error = Error::Handle(); 8350 Error& error = Error::Handle();
8351 resolved_type_class = ResolveClassInPrefixScope( 8351 resolved_type_class = ResolveClassInPrefixScope(
8352 unresolved_class.token_pos(), 8352 unresolved_class.token_pos(),
8353 lib_prefix, 8353 lib_prefix,
8354 unresolved_class_name, 8354 unresolved_class_name,
8355 &error); 8355 &error);
8356 if (!error.IsNull()) { 8356 if (!error.IsNull()) {
8357 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) || 8357 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) ||
8358 FLAG_error_on_malformed_type) { 8358 FLAG_error_on_bad_type) {
8359 *type = ClassFinalizer::NewFinalizedMalformedType( 8359 *type = ClassFinalizer::NewFinalizedMalformedType(
8360 error, 8360 error,
8361 scope_class, 8361 scope_class,
8362 unresolved_class.token_pos(), 8362 unresolved_class.token_pos(),
8363 "cannot resolve class '%s'", 8363 "cannot resolve class '%s'",
8364 unresolved_class_name.ToCString()); 8364 unresolved_class_name.ToCString());
8365 } else { 8365 } else {
8366 // Map the malformed type to dynamic and ignore type arguments. 8366 // Map the malformed type to dynamic and ignore type arguments.
8367 *type = Type::DynamicType(); 8367 *type = Type::DynamicType();
8368 } 8368 }
8369 return; 8369 return;
8370 } 8370 }
8371 } 8371 }
8372 // At this point, we can only have a parameterized_type. 8372 // At this point, we can only have a parameterized_type.
8373 const Type& parameterized_type = Type::Cast(*type); 8373 const Type& parameterized_type = Type::Cast(*type);
8374 if (!resolved_type_class.IsNull()) { 8374 if (!resolved_type_class.IsNull()) {
8375 // Replace unresolved class with resolved type class. 8375 // Replace unresolved class with resolved type class.
8376 parameterized_type.set_type_class(resolved_type_class); 8376 parameterized_type.set_type_class(resolved_type_class);
8377 } else if (finalization >= ClassFinalizer::kCanonicalize) { 8377 } else if (finalization >= ClassFinalizer::kCanonicalize) {
8378 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) || 8378 if ((finalization == ClassFinalizer::kCanonicalizeWellFormed) ||
8379 FLAG_error_on_malformed_type) { 8379 FLAG_error_on_bad_type) {
8380 ClassFinalizer::FinalizeMalformedType( 8380 ClassFinalizer::FinalizeMalformedType(
8381 Error::Handle(), // No previous error. 8381 Error::Handle(), // No previous error.
8382 scope_class, 8382 scope_class,
8383 parameterized_type, 8383 parameterized_type,
8384 "type '%s' is not loaded", 8384 "type '%s' is not loaded",
8385 String::Handle(parameterized_type.UserVisibleName()).ToCString()); 8385 String::Handle(parameterized_type.UserVisibleName()).ToCString());
8386 } else { 8386 } else {
8387 // Map the malformed type to dynamic and ignore type arguments. 8387 // Map the malformed type to dynamic and ignore type arguments.
8388 *type = Type::DynamicType(); 8388 *type = Type::DynamicType();
8389 } 8389 }
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
9170 AbstractTypeArguments& list_type_arguments = 9170 AbstractTypeArguments& list_type_arguments =
9171 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); 9171 AbstractTypeArguments::ZoneHandle(type_arguments.raw());
9172 // If no type argument vector is provided, leave it as null, which is 9172 // If no type argument vector is provided, leave it as null, which is
9173 // equivalent to using dynamic as the type argument for the element type. 9173 // equivalent to using dynamic as the type argument for the element type.
9174 if (!list_type_arguments.IsNull()) { 9174 if (!list_type_arguments.IsNull()) {
9175 ASSERT(list_type_arguments.Length() > 0); 9175 ASSERT(list_type_arguments.Length() > 0);
9176 // List literals take a single type argument. 9176 // List literals take a single type argument.
9177 if (list_type_arguments.Length() == 1) { 9177 if (list_type_arguments.Length() == 1) {
9178 element_type = list_type_arguments.TypeAt(0); 9178 element_type = list_type_arguments.TypeAt(0);
9179 } else { 9179 } else {
9180 if (FLAG_error_on_malformed_type) { 9180 if (FLAG_error_on_bad_type) {
9181 ErrorMsg(type_pos, 9181 ErrorMsg(type_pos,
9182 "a list literal takes one type argument specifying " 9182 "a list literal takes one type argument specifying "
9183 "the element type"); 9183 "the element type");
9184 } 9184 }
9185 // Ignore type arguments. 9185 // Ignore type arguments.
9186 list_type_arguments = AbstractTypeArguments::null(); 9186 list_type_arguments = AbstractTypeArguments::null();
9187 } 9187 }
9188 if (is_const && !element_type.IsInstantiated()) { 9188 if (is_const && !element_type.IsInstantiated()) {
9189 ErrorMsg(type_pos, 9189 ErrorMsg(type_pos,
9190 "the type argument of a constant list literal cannot include " 9190 "the type argument of a constant list literal cannot include "
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
9368 // Map literals take two type arguments. 9368 // Map literals take two type arguments.
9369 if (map_type_arguments.Length() == 2) { 9369 if (map_type_arguments.Length() == 2) {
9370 key_type = map_type_arguments.TypeAt(0); 9370 key_type = map_type_arguments.TypeAt(0);
9371 value_type = map_type_arguments.TypeAt(1); 9371 value_type = map_type_arguments.TypeAt(1);
9372 if (is_const && !type_arguments.IsInstantiated()) { 9372 if (is_const && !type_arguments.IsInstantiated()) {
9373 ErrorMsg(type_pos, 9373 ErrorMsg(type_pos,
9374 "the type arguments of a constant map literal cannot include " 9374 "the type arguments of a constant map literal cannot include "
9375 "a type variable"); 9375 "a type variable");
9376 } 9376 }
9377 if (key_type.IsMalformed()) { 9377 if (key_type.IsMalformed()) {
9378 if (FLAG_error_on_malformed_type) { 9378 if (FLAG_error_on_bad_type) {
9379 ErrorMsg(Error::Handle(key_type.malformed_error())); 9379 ErrorMsg(Error::Handle(key_type.malformed_error()));
9380 } 9380 }
9381 // Map malformed key type to dynamic. 9381 // Map malformed key type to dynamic.
9382 key_type = Type::DynamicType(); 9382 key_type = Type::DynamicType();
9383 map_type_arguments.SetTypeAt(0, key_type); 9383 map_type_arguments.SetTypeAt(0, key_type);
9384 } 9384 }
9385 if (value_type.IsMalformed()) { 9385 if (value_type.IsMalformed()) {
9386 if (FLAG_error_on_malformed_type) { 9386 if (FLAG_error_on_bad_type) {
9387 ErrorMsg(Error::Handle(value_type.malformed_error())); 9387 ErrorMsg(Error::Handle(value_type.malformed_error()));
9388 } 9388 }
9389 // Map malformed value type to dynamic. 9389 // Map malformed value type to dynamic.
9390 value_type = Type::DynamicType(); 9390 value_type = Type::DynamicType();
9391 map_type_arguments.SetTypeAt(1, value_type); 9391 map_type_arguments.SetTypeAt(1, value_type);
9392 } 9392 }
9393 } else { 9393 } else {
9394 if (FLAG_error_on_malformed_type) { 9394 if (FLAG_error_on_bad_type) {
9395 ErrorMsg(type_pos, 9395 ErrorMsg(type_pos,
9396 "a map literal takes two type arguments specifying " 9396 "a map literal takes two type arguments specifying "
9397 "the key type and the value type"); 9397 "the key type and the value type");
9398 } 9398 }
9399 // Ignore type arguments. 9399 // Ignore type arguments.
9400 map_type_arguments = AbstractTypeArguments::null(); 9400 map_type_arguments = AbstractTypeArguments::null();
9401 } 9401 }
9402 } 9402 }
9403 ASSERT((map_type_arguments.IsNull() && 9403 ASSERT((map_type_arguments.IsNull() &&
9404 key_type.IsDynamicType() && value_type.IsDynamicType()) || 9404 key_type.IsDynamicType() && value_type.IsDynamicType()) ||
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
9618 if (type.IsTypeParameter() || type.IsDynamicType()) { 9618 if (type.IsTypeParameter() || type.IsDynamicType()) {
9619 // Replace the type with a malformed type. 9619 // Replace the type with a malformed type.
9620 type = ClassFinalizer::NewFinalizedMalformedType( 9620 type = ClassFinalizer::NewFinalizedMalformedType(
9621 Error::Handle(), // No previous error. 9621 Error::Handle(), // No previous error.
9622 current_class(), 9622 current_class(),
9623 type_pos, 9623 type_pos,
9624 "%s'%s' cannot be instantiated", 9624 "%s'%s' cannot be instantiated",
9625 type.IsTypeParameter() ? "type parameter " : "", 9625 type.IsTypeParameter() ? "type parameter " : "",
9626 type.IsTypeParameter() ? 9626 type.IsTypeParameter() ?
9627 String::Handle(type.UserVisibleName()).ToCString() : "dynamic"); 9627 String::Handle(type.UserVisibleName()).ToCString() : "dynamic");
9628 } else if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) { 9628 } else if (FLAG_enable_type_checks || FLAG_error_on_bad_type) {
9629 Error& bound_error = Error::Handle(); 9629 Error& bound_error = Error::Handle();
9630 if (type.IsMalboundedWithError(&bound_error)) { 9630 if (type.IsMalboundedWithError(&bound_error)) {
9631 // Replace the type with a malformed type. 9631 // Replace the type with a malformed type.
9632 type = ClassFinalizer::NewFinalizedMalformedType( 9632 type = ClassFinalizer::NewFinalizedMalformedType(
9633 bound_error, 9633 bound_error,
9634 current_class(), 9634 current_class(),
9635 type_pos, 9635 type_pos,
9636 "malbounded type '%s' cannot be instantiated", 9636 "malbounded type '%s' cannot be instantiated",
9637 String::Handle(type.UserVisibleName()).ToCString()); 9637 String::Handle(type.UserVisibleName()).ToCString());
9638 } 9638 }
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
10420 void Parser::SkipQualIdent() { 10420 void Parser::SkipQualIdent() {
10421 ASSERT(IsIdentifier()); 10421 ASSERT(IsIdentifier());
10422 ConsumeToken(); 10422 ConsumeToken();
10423 if (CurrentToken() == Token::kPERIOD) { 10423 if (CurrentToken() == Token::kPERIOD) {
10424 ConsumeToken(); // Consume the kPERIOD token. 10424 ConsumeToken(); // Consume the kPERIOD token.
10425 ExpectIdentifier("identifier expected after '.'"); 10425 ExpectIdentifier("identifier expected after '.'");
10426 } 10426 }
10427 } 10427 }
10428 10428
10429 } // namespace dart 10429 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_linux.cc ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698