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

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

Issue 10854191: Require two type arguments for map literals (issue 4522). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 | « pkg/logging/logging.dart ('k') | samples/markdown/ast.dart » ('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 "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 10 matching lines...) Expand all
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_catch, false, "Warning on legacy catch syntax"); 30 DEFINE_FLAG(bool, warn_legacy_catch, false, "Warning on legacy catch syntax");
31 DEFINE_FLAG(bool, warn_legacy_map_literal, false,
32 "Warning on legacy map literal syntax (single type argument)");
31 33
32 static void CheckedModeHandler(bool value) { 34 static void CheckedModeHandler(bool value) {
33 FLAG_enable_asserts = value; 35 FLAG_enable_asserts = value;
34 FLAG_enable_type_checks = value; 36 FLAG_enable_type_checks = value;
35 } 37 }
36 38
37 DEFINE_FLAG_HANDLER(CheckedModeHandler, 39 DEFINE_FLAG_HANDLER(CheckedModeHandler,
38 enable_checked_mode, 40 enable_checked_mode,
39 "Enabled checked mode."); 41 "Enabled checked mode.");
40 42
(...skipping 8019 matching lines...) Expand 10 before | Expand all | Expand 10 after
8060 const intptr_t literal_pos = TokenPos(); 8062 const intptr_t literal_pos = TokenPos();
8061 ConsumeToken(); 8063 ConsumeToken();
8062 8064
8063 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); 8065 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType());
8064 AbstractTypeArguments& map_type_arguments = 8066 AbstractTypeArguments& map_type_arguments =
8065 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); 8067 AbstractTypeArguments::ZoneHandle(type_arguments.raw());
8066 // If no type argument vector is provided, leave it as null, which is 8068 // If no type argument vector is provided, leave it as null, which is
8067 // equivalent to using Dynamic as the type argument for the value type. 8069 // equivalent to using Dynamic as the type argument for the value type.
8068 if (!map_type_arguments.IsNull()) { 8070 if (!map_type_arguments.IsNull()) {
8069 ASSERT(map_type_arguments.Length() > 0); 8071 ASSERT(map_type_arguments.Length() > 0);
8070 // Map literals take a single type argument. 8072 // Map literals take two type arguments.
8071 value_type = map_type_arguments.TypeAt(0); 8073 if (map_type_arguments.Length() < 2) {
8072 if (map_type_arguments.Length() > 1) { 8074 // TODO(hausner): Remove legacy syntax support.
8073 // We temporarily accept two type arguments, as long as the first one is 8075 // We temporarily accept a single type argument.
8074 // type String. 8076 if (FLAG_warn_legacy_map_literal) {
8075 if (map_type_arguments.Length() != 2) { 8077 Warning(type_pos,
8076 ErrorMsg(type_pos, 8078 "a map literal takes two type arguments specifying "
8077 "a map literal takes one type argument specifying " 8079 "the key type and the value type");
8078 "the value type");
8079 } 8080 }
8080 if (!value_type.IsStringInterface()) {
8081 ErrorMsg(type_pos,
8082 "the key type of a map literal is implicitly 'String'");
8083 }
8084 Warning(type_pos,
8085 "a map literal takes one type argument specifying "
8086 "the value type");
8087 value_type = map_type_arguments.TypeAt(1);
8088 } else {
8089 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); 8081 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2));
8090 type_array.SetTypeAt(0, Type::Handle(Type::StringInterface())); 8082 type_array.SetTypeAt(0, Type::Handle(Type::StringInterface()));
8091 type_array.SetTypeAt(1, value_type); 8083 type_array.SetTypeAt(1, value_type);
8092 map_type_arguments = type_array.raw(); 8084 map_type_arguments = type_array.raw();
8085 } else if (map_type_arguments.Length() > 2) {
8086 ErrorMsg(type_pos,
8087 "a map literal takes two type arguments specifying "
8088 "the key type and the value type");
8089 } else {
8090 const AbstractType& key_type =
8091 AbstractType::Handle(map_type_arguments.TypeAt(0));
8092 value_type = map_type_arguments.TypeAt(1);
8093 if (!key_type.IsStringInterface()) {
8094 ErrorMsg(type_pos, "the key type of a map literal must be 'String'");
8095 }
8093 } 8096 }
8094 if (is_const && !value_type.IsInstantiated()) { 8097 if (is_const && !value_type.IsInstantiated()) {
8095 ErrorMsg(type_pos, 8098 ErrorMsg(type_pos,
8096 "the type argument of a constant map literal cannot include " 8099 "the type argument of a constant map literal cannot include "
8097 "a type variable"); 8100 "a type variable");
8098 } 8101 }
8099 } 8102 }
8100 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); 8103 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2));
8101 map_type_arguments ^= map_type_arguments.Canonicalize(); 8104 map_type_arguments ^= map_type_arguments.Canonicalize();
8102 8105
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after
9082 void Parser::SkipQualIdent() { 9085 void Parser::SkipQualIdent() {
9083 ASSERT(IsIdentifier()); 9086 ASSERT(IsIdentifier());
9084 ConsumeToken(); 9087 ConsumeToken();
9085 if (CurrentToken() == Token::kPERIOD) { 9088 if (CurrentToken() == Token::kPERIOD) {
9086 ConsumeToken(); // Consume the kPERIOD token. 9089 ConsumeToken(); // Consume the kPERIOD token.
9087 ExpectIdentifier("identifier expected after '.'"); 9090 ExpectIdentifier("identifier expected after '.'");
9088 } 9091 }
9089 } 9092 }
9090 9093
9091 } // namespace dart 9094 } // namespace dart
OLDNEW
« no previous file with comments | « pkg/logging/logging.dart ('k') | samples/markdown/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698