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

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

Issue 10368004: Properly set the element type of literal lists. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
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 7294 matching lines...) Expand 10 before | Expand all | Expand 10 after
7305 if (is_const && !element_type.IsInstantiated()) { 7305 if (is_const && !element_type.IsInstantiated()) {
7306 ErrorMsg(type_pos, 7306 ErrorMsg(type_pos,
7307 "the type argument of a constant list literal cannot include " 7307 "the type argument of a constant list literal cannot include "
7308 "a type variable"); 7308 "a type variable");
7309 } 7309 }
7310 } 7310 }
7311 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); 7311 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1));
7312 7312
7313 // Parse the list elements. Note: there may be an optional extra 7313 // Parse the list elements. Note: there may be an optional extra
7314 // comma after the last element. 7314 // comma after the last element.
7315 ArrayNode* list = 7315 ArrayNode* list = new ArrayNode(token_index_, type_arguments);
7316 new ArrayNode(token_index_, TypeArguments::ZoneHandle());
7317 if (!is_empty_literal) { 7316 if (!is_empty_literal) {
7318 const bool saved_mode = SetAllowFunctionLiterals(true); 7317 const bool saved_mode = SetAllowFunctionLiterals(true);
7319 const String& dst_name = String::ZoneHandle( 7318 const String& dst_name = String::ZoneHandle(
7320 String::NewSymbol("list literal element")); 7319 String::NewSymbol("list literal element"));
7321 while (CurrentToken() != Token::kRBRACK) { 7320 while (CurrentToken() != Token::kRBRACK) {
7322 const intptr_t element_pos = token_index_; 7321 const intptr_t element_pos = token_index_;
7323 AstNode* element = ParseExpr(is_const); 7322 AstNode* element = ParseExpr(is_const);
7324 if (FLAG_enable_type_checks && 7323 if (FLAG_enable_type_checks &&
7325 !is_const && 7324 !is_const &&
7326 !element_type.IsDynamicType()) { 7325 !element_type.IsDynamicType()) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
7471 ErrorMsg(type_pos, 7470 ErrorMsg(type_pos,
7472 "the type argument of a constant map literal cannot include " 7471 "the type argument of a constant map literal cannot include "
7473 "a type variable"); 7472 "a type variable");
7474 } 7473 }
7475 } 7474 }
7476 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); 7475 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2));
7477 map_type_arguments ^= map_type_arguments.Canonicalize(); 7476 map_type_arguments ^= map_type_arguments.Canonicalize();
7478 7477
7479 // Parse the map entries. Note: there may be an optional extra 7478 // Parse the map entries. Note: there may be an optional extra
7480 // comma after the last entry. 7479 // comma after the last entry.
7480 // The kv_pair array is temporary and of element type Dynamic. It is passed
7481 // to the factory to initialize a properly typed map.
7481 ArrayNode* kv_pairs = 7482 ArrayNode* kv_pairs =
7482 new ArrayNode(token_index_, TypeArguments::ZoneHandle()); 7483 new ArrayNode(token_index_, TypeArguments::ZoneHandle());
7483 const String& dst_name = String::ZoneHandle( 7484 const String& dst_name = String::ZoneHandle(
7484 String::NewSymbol("list literal element")); 7485 String::NewSymbol("list literal element"));
7485 while (CurrentToken() != Token::kRBRACE) { 7486 while (CurrentToken() != Token::kRBRACE) {
7486 AstNode* key = NULL; 7487 AstNode* key = NULL;
7487 if (CurrentToken() == Token::kSTRING) { 7488 if (CurrentToken() == Token::kSTRING) {
7488 key = ParseStringLiteral(); 7489 key = ParseStringLiteral();
7489 } 7490 }
7490 if (key == NULL) { 7491 if (key == NULL) {
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
8430 void Parser::SkipQualIdent() { 8431 void Parser::SkipQualIdent() {
8431 ASSERT(IsIdentifier()); 8432 ASSERT(IsIdentifier());
8432 ConsumeToken(); 8433 ConsumeToken();
8433 if (CurrentToken() == Token::kPERIOD) { 8434 if (CurrentToken() == Token::kPERIOD) {
8434 ConsumeToken(); // Consume the kPERIOD token. 8435 ConsumeToken(); // Consume the kPERIOD token.
8435 ExpectIdentifier("identifier expected after '.'"); 8436 ExpectIdentifier("identifier expected after '.'");
8436 } 8437 }
8437 } 8438 }
8438 8439
8439 } // namespace dart 8440 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698