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 | 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" |
11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
13 #include "vm/flags.h" | 13 #include "vm/flags.h" |
14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
16 #include "vm/native_entry.h" | 16 #include "vm/native_entry.h" |
17 #include "vm/object.h" | 17 #include "vm/object.h" |
18 #include "vm/object_store.h" | 18 #include "vm/object_store.h" |
19 #include "vm/resolver.h" | 19 #include "vm/resolver.h" |
20 #include "vm/scopes.h" | 20 #include "vm/scopes.h" |
21 #include "vm/symbols.h" | 21 #include "vm/symbols.h" |
22 | 22 |
23 namespace dart { | 23 namespace dart { |
24 | 24 |
25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); | 25 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements."); |
26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); | 26 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks."); |
27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); | 27 DEFINE_FLAG(bool, trace_parser, false, "Trace parser operations."); |
28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); | 28 DEFINE_FLAG(bool, warning_as_error, false, "Treat warnings as errors."); |
29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); | 29 DEFINE_FLAG(bool, silent_warnings, false, "Silence warnings."); |
30 DEFINE_FLAG(bool, warn_legacy_map_literal, false, | |
31 "Warning on legacy map literal syntax (single type argument)"); | |
32 | 30 |
33 static void CheckedModeHandler(bool value) { | 31 static void CheckedModeHandler(bool value) { |
34 FLAG_enable_asserts = value; | 32 FLAG_enable_asserts = value; |
35 FLAG_enable_type_checks = value; | 33 FLAG_enable_type_checks = value; |
36 } | 34 } |
37 | 35 |
38 // --enable-checked-mode and --checked both enable checked mode which is | 36 // --enable-checked-mode and --checked both enable checked mode which is |
39 // equivalent to setting --enable-asserts and --enable-type-checks. | 37 // equivalent to setting --enable-asserts and --enable-type-checks. |
40 DEFINE_FLAG_HANDLER(CheckedModeHandler, | 38 DEFINE_FLAG_HANDLER(CheckedModeHandler, |
41 enable_checked_mode, | 39 enable_checked_mode, |
(...skipping 8589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8631 ConsumeToken(); | 8629 ConsumeToken(); |
8632 | 8630 |
8633 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); | 8631 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); |
8634 AbstractTypeArguments& map_type_arguments = | 8632 AbstractTypeArguments& map_type_arguments = |
8635 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); | 8633 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); |
8636 // If no type argument vector is provided, leave it as null, which is | 8634 // If no type argument vector is provided, leave it as null, which is |
8637 // equivalent to using dynamic as the type argument for the value type. | 8635 // equivalent to using dynamic as the type argument for the value type. |
8638 if (!map_type_arguments.IsNull()) { | 8636 if (!map_type_arguments.IsNull()) { |
8639 ASSERT(map_type_arguments.Length() > 0); | 8637 ASSERT(map_type_arguments.Length() > 0); |
8640 // Map literals take two type arguments. | 8638 // Map literals take two type arguments. |
8641 if (map_type_arguments.Length() < 2) { | 8639 if (map_type_arguments.Length() != 2) { |
8642 // TODO(hausner): Remove legacy syntax support. | |
8643 // We temporarily accept a single type argument. | |
8644 if (FLAG_warn_legacy_map_literal) { | |
8645 Warning(type_pos, | |
8646 "a map literal takes two type arguments specifying " | |
8647 "the key type and the value type"); | |
8648 } | |
8649 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); | |
8650 type_array.SetTypeAt(0, Type::Handle(Type::StringType())); | |
8651 type_array.SetTypeAt(1, value_type); | |
8652 map_type_arguments = type_array.raw(); | |
8653 } else if (map_type_arguments.Length() > 2) { | |
8654 ErrorMsg(type_pos, | 8640 ErrorMsg(type_pos, |
8655 "a map literal takes two type arguments specifying " | 8641 "a map literal takes two type arguments specifying " |
8656 "the key type and the value type"); | 8642 "the key type and the value type"); |
8657 } else { | 8643 } |
8658 const AbstractType& key_type = | 8644 const AbstractType& key_type = |
8659 AbstractType::Handle(map_type_arguments.TypeAt(0)); | 8645 AbstractType::Handle(map_type_arguments.TypeAt(0)); |
8660 value_type = map_type_arguments.TypeAt(1); | 8646 value_type = map_type_arguments.TypeAt(1); |
8661 if (!key_type.IsStringType()) { | 8647 if (!key_type.IsStringType()) { |
8662 ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); | 8648 ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); |
8663 } | |
8664 } | 8649 } |
8665 if (is_const && !value_type.IsInstantiated()) { | 8650 if (is_const && !value_type.IsInstantiated()) { |
8666 ErrorMsg(type_pos, | 8651 ErrorMsg(type_pos, |
8667 "the type argument of a constant map literal cannot include " | 8652 "the type argument of a constant map literal cannot include " |
8668 "a type variable"); | 8653 "a type variable"); |
8669 } | 8654 } |
8670 } | 8655 } |
8671 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 8656 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
8672 map_type_arguments ^= map_type_arguments.Canonicalize(); | 8657 map_type_arguments ^= map_type_arguments.Canonicalize(); |
8673 | 8658 |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9675 void Parser::SkipQualIdent() { | 9660 void Parser::SkipQualIdent() { |
9676 ASSERT(IsIdentifier()); | 9661 ASSERT(IsIdentifier()); |
9677 ConsumeToken(); | 9662 ConsumeToken(); |
9678 if (CurrentToken() == Token::kPERIOD) { | 9663 if (CurrentToken() == Token::kPERIOD) { |
9679 ConsumeToken(); // Consume the kPERIOD token. | 9664 ConsumeToken(); // Consume the kPERIOD token. |
9680 ExpectIdentifier("identifier expected after '.'"); | 9665 ExpectIdentifier("identifier expected after '.'"); |
9681 } | 9666 } |
9682 } | 9667 } |
9683 | 9668 |
9684 } // namespace dart | 9669 } // namespace dart |
OLD | NEW |