Chromium Code Reviews| 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" |
| (...skipping 8049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8060 const intptr_t literal_pos = TokenPos(); | 8060 const intptr_t literal_pos = TokenPos(); |
| 8061 ConsumeToken(); | 8061 ConsumeToken(); |
| 8062 | 8062 |
| 8063 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); | 8063 AbstractType& value_type = Type::ZoneHandle(Type::DynamicType()); |
| 8064 AbstractTypeArguments& map_type_arguments = | 8064 AbstractTypeArguments& map_type_arguments = |
| 8065 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); | 8065 AbstractTypeArguments::ZoneHandle(type_arguments.raw()); |
| 8066 // If no type argument vector is provided, leave it as null, which is | 8066 // 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. | 8067 // equivalent to using Dynamic as the type argument for the value type. |
| 8068 if (!map_type_arguments.IsNull()) { | 8068 if (!map_type_arguments.IsNull()) { |
| 8069 ASSERT(map_type_arguments.Length() > 0); | 8069 ASSERT(map_type_arguments.Length() > 0); |
| 8070 // Map literals take a single type argument. | 8070 // Map literals take two type arguments. |
| 8071 value_type = map_type_arguments.TypeAt(0); | 8071 if (map_type_arguments.Length() < 2) { |
| 8072 if (map_type_arguments.Length() > 1) { | 8072 // We temporarily accept a single type argument. |
| 8073 // We temporarily accept two type arguments, as long as the first one is | |
| 8074 // type String. | |
| 8075 if (map_type_arguments.Length() != 2) { | |
| 8076 ErrorMsg(type_pos, | |
| 8077 "a map literal takes one type argument specifying " | |
| 8078 "the value type"); | |
| 8079 } | |
| 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, | 8073 Warning(type_pos, |
|
hausner
2012/08/16 20:02:39
As Peter notes, I would guard this with a separate
regis
2012/08/16 20:11:00
Done. I have hidden the warning behind --warn_lega
| |
| 8085 "a map literal takes one type argument specifying " | 8074 "a map literal takes two type arguments specifying " |
| 8086 "the value type"); | 8075 "the key type and the value type"); |
| 8087 value_type = map_type_arguments.TypeAt(1); | |
| 8088 } else { | |
| 8089 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); | 8076 TypeArguments& type_array = TypeArguments::Handle(TypeArguments::New(2)); |
| 8090 type_array.SetTypeAt(0, Type::Handle(Type::StringInterface())); | 8077 type_array.SetTypeAt(0, Type::Handle(Type::StringInterface())); |
| 8091 type_array.SetTypeAt(1, value_type); | 8078 type_array.SetTypeAt(1, value_type); |
| 8092 map_type_arguments = type_array.raw(); | 8079 map_type_arguments = type_array.raw(); |
| 8080 } else if (map_type_arguments.Length() > 2) { | |
| 8081 ErrorMsg(type_pos, | |
| 8082 "a map literal takes two type arguments specifying " | |
| 8083 "the key type and the value type"); | |
| 8084 } else { | |
| 8085 const AbstractType& key_type = | |
| 8086 AbstractType::Handle(map_type_arguments.TypeAt(0)); | |
| 8087 value_type = map_type_arguments.TypeAt(1); | |
| 8088 if (!key_type.IsStringInterface()) { | |
| 8089 ErrorMsg(type_pos, "the key type of a map literal must be 'String'"); | |
| 8090 } | |
| 8093 } | 8091 } |
| 8094 if (is_const && !value_type.IsInstantiated()) { | 8092 if (is_const && !value_type.IsInstantiated()) { |
| 8095 ErrorMsg(type_pos, | 8093 ErrorMsg(type_pos, |
| 8096 "the type argument of a constant map literal cannot include " | 8094 "the type argument of a constant map literal cannot include " |
| 8097 "a type variable"); | 8095 "a type variable"); |
| 8098 } | 8096 } |
| 8099 } | 8097 } |
| 8100 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); | 8098 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); |
| 8101 map_type_arguments ^= map_type_arguments.Canonicalize(); | 8099 map_type_arguments ^= map_type_arguments.Canonicalize(); |
| 8102 | 8100 |
| (...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9082 void Parser::SkipQualIdent() { | 9080 void Parser::SkipQualIdent() { |
| 9083 ASSERT(IsIdentifier()); | 9081 ASSERT(IsIdentifier()); |
| 9084 ConsumeToken(); | 9082 ConsumeToken(); |
| 9085 if (CurrentToken() == Token::kPERIOD) { | 9083 if (CurrentToken() == Token::kPERIOD) { |
| 9086 ConsumeToken(); // Consume the kPERIOD token. | 9084 ConsumeToken(); // Consume the kPERIOD token. |
| 9087 ExpectIdentifier("identifier expected after '.'"); | 9085 ExpectIdentifier("identifier expected after '.'"); |
| 9088 } | 9086 } |
| 9089 } | 9087 } |
| 9090 | 9088 |
| 9091 } // namespace dart | 9089 } // namespace dart |
| OLD | NEW |