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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED | 8 #ifndef DART_PRECOMPILED |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 12661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12672 ExpectToken(Token::kRBRACK); | 12672 ExpectToken(Token::kRBRACK); |
12673 SetAllowFunctionLiterals(saved_mode); | 12673 SetAllowFunctionLiterals(saved_mode); |
12674 } | 12674 } |
12675 | 12675 |
12676 if (is_const) { | 12676 if (is_const) { |
12677 // Allocate and initialize the const list at compile time. | 12677 // Allocate and initialize the const list at compile time. |
12678 Array& const_list = Array::ZoneHandle(Z, | 12678 Array& const_list = Array::ZoneHandle(Z, |
12679 Array::New(element_list.length(), Heap::kOld)); | 12679 Array::New(element_list.length(), Heap::kOld)); |
12680 const_list.SetTypeArguments( | 12680 const_list.SetTypeArguments( |
12681 TypeArguments::Handle(Z, list_type_arguments.Canonicalize())); | 12681 TypeArguments::Handle(Z, list_type_arguments.Canonicalize())); |
12682 Error& malformed_error = Error::Handle(Z); | 12682 Error& bound_error = Error::Handle(Z); |
12683 for (int i = 0; i < element_list.length(); i++) { | 12683 for (int i = 0; i < element_list.length(); i++) { |
12684 AstNode* elem = element_list[i]; | 12684 AstNode* elem = element_list[i]; |
12685 // Arguments have been evaluated to a literal value already. | 12685 // Arguments have been evaluated to a literal value already. |
12686 ASSERT(elem->IsLiteralNode()); | 12686 ASSERT(elem->IsLiteralNode()); |
12687 ASSERT(!is_top_level_); // We cannot check unresolved types. | 12687 ASSERT(!is_top_level_); // We cannot check unresolved types. |
12688 if (I->flags().type_checks() && | 12688 if (I->flags().type_checks() && |
12689 !element_type.IsDynamicType() && | 12689 !element_type.IsDynamicType() && |
12690 (!elem->AsLiteralNode()->literal().IsNull() && | 12690 (!elem->AsLiteralNode()->literal().IsNull() && |
12691 !elem->AsLiteralNode()->literal().IsInstanceOf( | 12691 !elem->AsLiteralNode()->literal().IsInstanceOf( |
12692 element_type, | 12692 element_type, |
12693 TypeArguments::Handle(Z), | 12693 TypeArguments::Handle(Z), |
12694 &malformed_error))) { | 12694 &bound_error))) { |
12695 // If the failure is due to a malformed type error, display it instead. | 12695 // If the failure is due to a bound error, display it instead. |
12696 if (!malformed_error.IsNull()) { | 12696 if (!bound_error.IsNull()) { |
12697 ReportError(malformed_error); | 12697 ReportError(bound_error); |
12698 } else { | 12698 } else { |
12699 ReportError(elem->AsLiteralNode()->token_pos(), | 12699 ReportError(elem->AsLiteralNode()->token_pos(), |
12700 "list literal element at index %d must be " | 12700 "list literal element at index %d must be " |
12701 "a constant of type '%s'", | 12701 "a constant of type '%s'", |
12702 i, | 12702 i, |
12703 String::Handle(Z, | 12703 String::Handle(Z, |
12704 element_type.UserVisibleName()).ToCString()); | 12704 element_type.UserVisibleName()).ToCString()); |
12705 } | 12705 } |
12706 } | 12706 } |
12707 const_list.SetAt(i, elem->AsLiteralNode()->literal()); | 12707 const_list.SetAt(i, elem->AsLiteralNode()->literal()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12898 | 12898 |
12899 if (is_const) { | 12899 if (is_const) { |
12900 // Create the key-value pair array, canonicalize it and then create | 12900 // Create the key-value pair array, canonicalize it and then create |
12901 // the immutable map object with it. This all happens at compile time. | 12901 // the immutable map object with it. This all happens at compile time. |
12902 // The resulting immutable map object is returned as a literal. | 12902 // The resulting immutable map object is returned as a literal. |
12903 | 12903 |
12904 // First, create the canonicalized key-value pair array. | 12904 // First, create the canonicalized key-value pair array. |
12905 Array& key_value_array = | 12905 Array& key_value_array = |
12906 Array::ZoneHandle(Z, Array::New(kv_pairs_list.length(), Heap::kOld)); | 12906 Array::ZoneHandle(Z, Array::New(kv_pairs_list.length(), Heap::kOld)); |
12907 AbstractType& arg_type = Type::Handle(Z); | 12907 AbstractType& arg_type = Type::Handle(Z); |
12908 Error& malformed_error = Error::Handle(Z); | 12908 Error& bound_error = Error::Handle(Z); |
12909 for (int i = 0; i < kv_pairs_list.length(); i++) { | 12909 for (int i = 0; i < kv_pairs_list.length(); i++) { |
12910 AstNode* arg = kv_pairs_list[i]; | 12910 AstNode* arg = kv_pairs_list[i]; |
12911 // Arguments have been evaluated to a literal value already. | 12911 // Arguments have been evaluated to a literal value already. |
12912 ASSERT(arg->IsLiteralNode()); | 12912 ASSERT(arg->IsLiteralNode()); |
12913 ASSERT(!is_top_level_); // We cannot check unresolved types. | 12913 ASSERT(!is_top_level_); // We cannot check unresolved types. |
12914 if (I->flags().type_checks()) { | 12914 if (I->flags().type_checks()) { |
12915 if ((i % 2) == 0) { | 12915 if ((i % 2) == 0) { |
12916 // Check key type. | 12916 // Check key type. |
12917 arg_type = key_type.raw(); | 12917 arg_type = key_type.raw(); |
12918 } else { | 12918 } else { |
12919 // Check value type. | 12919 // Check value type. |
12920 arg_type = value_type.raw(); | 12920 arg_type = value_type.raw(); |
12921 } | 12921 } |
12922 if (!arg_type.IsDynamicType() && | 12922 if (!arg_type.IsDynamicType() && |
12923 (!arg->AsLiteralNode()->literal().IsNull() && | 12923 (!arg->AsLiteralNode()->literal().IsNull() && |
12924 !arg->AsLiteralNode()->literal().IsInstanceOf( | 12924 !arg->AsLiteralNode()->literal().IsInstanceOf( |
12925 arg_type, | 12925 arg_type, |
12926 Object::null_type_arguments(), | 12926 Object::null_type_arguments(), |
12927 &malformed_error))) { | 12927 &bound_error))) { |
12928 // If the failure is due to a malformed type error, display it. | 12928 // If the failure is due to a bound error, display it. |
12929 if (!malformed_error.IsNull()) { | 12929 if (!bound_error.IsNull()) { |
12930 ReportError(malformed_error); | 12930 ReportError(bound_error); |
12931 } else { | 12931 } else { |
12932 ReportError(arg->AsLiteralNode()->token_pos(), | 12932 ReportError(arg->AsLiteralNode()->token_pos(), |
12933 "map literal %s at index %d must be " | 12933 "map literal %s at index %d must be " |
12934 "a constant of type '%s'", | 12934 "a constant of type '%s'", |
12935 ((i % 2) == 0) ? "key" : "value", | 12935 ((i % 2) == 0) ? "key" : "value", |
12936 i >> 1, | 12936 i >> 1, |
12937 String::Handle(Z, | 12937 String::Handle(Z, |
12938 arg_type.UserVisibleName()).ToCString()); | 12938 arg_type.UserVisibleName()).ToCString()); |
12939 } | 12939 } |
12940 } | 12940 } |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13534 ReportErrors(Error::Cast(constructor_result), | 13534 ReportErrors(Error::Cast(constructor_result), |
13535 script_, new_pos, | 13535 script_, new_pos, |
13536 "error while evaluating const constructor"); | 13536 "error while evaluating const constructor"); |
13537 } | 13537 } |
13538 const_instance ^= constructor_result.raw(); | 13538 const_instance ^= constructor_result.raw(); |
13539 CacheConstantValue(new_pos, const_instance); | 13539 CacheConstantValue(new_pos, const_instance); |
13540 } | 13540 } |
13541 new_object = new(Z) LiteralNode(new_pos, const_instance); | 13541 new_object = new(Z) LiteralNode(new_pos, const_instance); |
13542 if (!type_bound.IsNull()) { | 13542 if (!type_bound.IsNull()) { |
13543 ASSERT(!type_bound.IsMalformed()); | 13543 ASSERT(!type_bound.IsMalformed()); |
13544 Error& malformed_error = Error::Handle(Z); | 13544 Error& bound_error = Error::Handle(Z); |
13545 ASSERT(!is_top_level_); // We cannot check unresolved types. | 13545 ASSERT(!is_top_level_); // We cannot check unresolved types. |
13546 if (!const_instance.IsInstanceOf(type_bound, | 13546 if (!const_instance.IsInstanceOf(type_bound, |
13547 TypeArguments::Handle(Z), | 13547 TypeArguments::Handle(Z), |
13548 &malformed_error)) { | 13548 &bound_error)) { |
13549 type_bound = ClassFinalizer::NewFinalizedMalformedType( | 13549 type_bound = ClassFinalizer::NewFinalizedMalformedType( |
13550 malformed_error, | 13550 bound_error, |
13551 script_, | 13551 script_, |
13552 new_pos, | 13552 new_pos, |
13553 "const factory result is not an instance of '%s'", | 13553 "const factory result is not an instance of '%s'", |
13554 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); | 13554 String::Handle(Z, type_bound.UserVisibleName()).ToCString()); |
13555 new_object = ThrowTypeError(new_pos, type_bound); | 13555 new_object = ThrowTypeError(new_pos, type_bound); |
13556 } | 13556 } |
13557 type_bound = AbstractType::null(); | 13557 type_bound = AbstractType::null(); |
13558 } | 13558 } |
13559 } else { | 13559 } else { |
13560 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); | 13560 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14396 const ArgumentListNode& function_args, | 14396 const ArgumentListNode& function_args, |
14397 const LocalVariable* temp_for_last_arg, | 14397 const LocalVariable* temp_for_last_arg, |
14398 bool is_super_invocation) { | 14398 bool is_super_invocation) { |
14399 UNREACHABLE(); | 14399 UNREACHABLE(); |
14400 return NULL; | 14400 return NULL; |
14401 } | 14401 } |
14402 | 14402 |
14403 } // namespace dart | 14403 } // namespace dart |
14404 | 14404 |
14405 #endif // DART_PRECOMPILED | 14405 #endif // DART_PRECOMPILED |
OLD | NEW |