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

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

Issue 10878042: Propagate type of list literal from parser to ast, graph, and optimizer. (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
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | 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 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 const String& function_name, 1247 const String& function_name,
1248 const ArgumentListNode& function_args) { 1248 const ArgumentListNode& function_args) {
1249 ASSERT(function_args.length() >= 1); // The receiver is the first argument. 1249 ASSERT(function_args.length() >= 1); // The receiver is the first argument.
1250 const intptr_t args_pos = function_args.token_pos(); 1250 const intptr_t args_pos = function_args.token_pos();
1251 ArgumentListNode* arguments = new ArgumentListNode(args_pos); 1251 ArgumentListNode* arguments = new ArgumentListNode(args_pos);
1252 arguments->Add(function_args.NodeAt(0)); 1252 arguments->Add(function_args.NodeAt(0));
1253 // The second argument is the original function name. 1253 // The second argument is the original function name.
1254 // TODO(regis): This will change once mirrors are supported. 1254 // TODO(regis): This will change once mirrors are supported.
1255 arguments->Add(new LiteralNode(args_pos, function_name)); 1255 arguments->Add(new LiteralNode(args_pos, function_name));
1256 // The third argument is an array containing the original function arguments. 1256 // The third argument is an array containing the original function arguments.
1257 ArrayNode* args_array = new ArrayNode(args_pos, TypeArguments::ZoneHandle()); 1257 ArrayNode* args_array = new ArrayNode(
1258 args_pos, Type::ZoneHandle(Type::ListInterface()));
1258 for (intptr_t i = 1; i < function_args.length(); i++) { 1259 for (intptr_t i = 1; i < function_args.length(); i++) {
1259 args_array->AddElement(function_args.NodeAt(i)); 1260 args_array->AddElement(function_args.NodeAt(i));
1260 } 1261 }
1261 arguments->Add(args_array); 1262 arguments->Add(args_array);
1262 return arguments; 1263 return arguments;
1263 } 1264 }
1264 1265
1265 1266
1266 AstNode* Parser::ParseSuperCall(const String& function_name) { 1267 AstNode* Parser::ParseSuperCall(const String& function_name) {
1267 TRACE_PARSER("ParseSuperCall"); 1268 TRACE_PARSER("ParseSuperCall");
(...skipping 6785 matching lines...) Expand 10 before | Expand all | Expand 10 after
8053 "a list literal takes one type argument specifying " 8054 "a list literal takes one type argument specifying "
8054 "the element type"); 8055 "the element type");
8055 } 8056 }
8056 if (is_const && !element_type.IsInstantiated()) { 8057 if (is_const && !element_type.IsInstantiated()) {
8057 ErrorMsg(type_pos, 8058 ErrorMsg(type_pos,
8058 "the type argument of a constant list literal cannot include " 8059 "the type argument of a constant list literal cannot include "
8059 "a type variable"); 8060 "a type variable");
8060 } 8061 }
8061 } 8062 }
8062 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1)); 8063 ASSERT(type_arguments.IsNull() || (type_arguments.Length() == 1));
8064 const Class& list_class = Class::Handle(
8065 Type::Handle(Type::ListInterface()).type_class());
8066 Type& type = Type::ZoneHandle(
8067 Type::New(list_class, type_arguments, type_pos));
8068 type ^= ClassFinalizer::FinalizeType(
8069 current_class(), type, ClassFinalizer::kCanonicalize);
8070 ArrayNode* list = new ArrayNode(TokenPos(), type);
8063 8071
8064 // Parse the list elements. Note: there may be an optional extra 8072 // Parse the list elements. Note: there may be an optional extra
8065 // comma after the last element. 8073 // comma after the last element.
8066 ArrayNode* list = new ArrayNode(TokenPos(), type_arguments);
8067 if (!is_empty_literal) { 8074 if (!is_empty_literal) {
8068 const bool saved_mode = SetAllowFunctionLiterals(true); 8075 const bool saved_mode = SetAllowFunctionLiterals(true);
8069 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); 8076 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8070 while (CurrentToken() != Token::kRBRACK) { 8077 while (CurrentToken() != Token::kRBRACK) {
8071 const intptr_t element_pos = TokenPos(); 8078 const intptr_t element_pos = TokenPos();
8072 AstNode* element = ParseExpr(is_const, kConsumeCascades); 8079 AstNode* element = ParseExpr(is_const, kConsumeCascades);
8073 if (FLAG_enable_type_checks && 8080 if (FLAG_enable_type_checks &&
8074 !is_const && 8081 !is_const &&
8075 !element_type.IsDynamicType()) { 8082 !element_type.IsDynamicType()) {
8076 element = new AssignableNode(element_pos, 8083 element = new AssignableNode(element_pos,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
8237 } 8244 }
8238 if (is_const && !value_type.IsInstantiated()) { 8245 if (is_const && !value_type.IsInstantiated()) {
8239 ErrorMsg(type_pos, 8246 ErrorMsg(type_pos,
8240 "the type argument of a constant map literal cannot include " 8247 "the type argument of a constant map literal cannot include "
8241 "a type variable"); 8248 "a type variable");
8242 } 8249 }
8243 } 8250 }
8244 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2)); 8251 ASSERT(map_type_arguments.IsNull() || (map_type_arguments.Length() == 2));
8245 map_type_arguments ^= map_type_arguments.Canonicalize(); 8252 map_type_arguments ^= map_type_arguments.Canonicalize();
8246 8253
8247 // Parse the map entries. Note: there may be an optional extra
8248 // comma after the last entry.
8249 // The kv_pair array is temporary and of element type Dynamic. It is passed 8254 // The kv_pair array is temporary and of element type Dynamic. It is passed
8250 // to the factory to initialize a properly typed map. 8255 // to the factory to initialize a properly typed map.
8251 ArrayNode* kv_pairs = 8256 ArrayNode* kv_pairs =
8252 new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); 8257 new ArrayNode(TokenPos(), Type::ZoneHandle(Type::ListInterface()));
8258
8259 // Parse the map entries. Note: there may be an optional extra
8260 // comma after the last entry.
8253 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement()); 8261 const String& dst_name = String::ZoneHandle(Symbols::ListLiteralElement());
8254 while (CurrentToken() != Token::kRBRACE) { 8262 while (CurrentToken() != Token::kRBRACE) {
8255 AstNode* key = NULL; 8263 AstNode* key = NULL;
8256 if (CurrentToken() == Token::kSTRING) { 8264 if (CurrentToken() == Token::kSTRING) {
8257 key = ParseStringLiteral(); 8265 key = ParseStringLiteral();
8258 } 8266 }
8259 if (key == NULL) { 8267 if (key == NULL) {
8260 ErrorMsg("map entry key must be string literal"); 8268 ErrorMsg("map entry key must be string literal");
8261 } else if (is_const && !key->IsLiteralNode()) { 8269 } else if (is_const && !key->IsLiteralNode()) {
8262 ErrorMsg("map entry key must be compile time constant string"); 8270 ErrorMsg("map entry key must be compile time constant string");
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
8700 if ((l1_token != Token::kSTRING) && 8708 if ((l1_token != Token::kSTRING) &&
8701 (l1_token != Token::kINTERPOL_VAR) && 8709 (l1_token != Token::kINTERPOL_VAR) &&
8702 (l1_token != Token::kINTERPOL_START)) { 8710 (l1_token != Token::kINTERPOL_START)) {
8703 // Common case: no interpolation. 8711 // Common case: no interpolation.
8704 primary = new LiteralNode(literal_start, *CurrentLiteral()); 8712 primary = new LiteralNode(literal_start, *CurrentLiteral());
8705 ConsumeToken(); 8713 ConsumeToken();
8706 return primary; 8714 return primary;
8707 } 8715 }
8708 // String interpolation needed. 8716 // String interpolation needed.
8709 bool is_compiletime_const = true; 8717 bool is_compiletime_const = true;
8710 ArrayNode* values = new ArrayNode(TokenPos(), TypeArguments::ZoneHandle()); 8718 ArrayNode* values = new ArrayNode(TokenPos(),
8719 Type::ZoneHandle(Type::ListInterface()));
8711 while (CurrentToken() == Token::kSTRING) { 8720 while (CurrentToken() == Token::kSTRING) {
8712 values->AddElement(new LiteralNode(TokenPos(), *CurrentLiteral())); 8721 values->AddElement(new LiteralNode(TokenPos(), *CurrentLiteral()));
8713 ConsumeToken(); 8722 ConsumeToken();
8714 while ((CurrentToken() == Token::kINTERPOL_VAR) || 8723 while ((CurrentToken() == Token::kINTERPOL_VAR) ||
8715 (CurrentToken() == Token::kINTERPOL_START)) { 8724 (CurrentToken() == Token::kINTERPOL_START)) {
8716 AstNode* expr = NULL; 8725 AstNode* expr = NULL;
8717 const intptr_t expr_pos = TokenPos(); 8726 const intptr_t expr_pos = TokenPos();
8718 if (CurrentToken() == Token::kINTERPOL_VAR) { 8727 if (CurrentToken() == Token::kINTERPOL_VAR) {
8719 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true); 8728 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true);
8720 ConsumeToken(); 8729 ConsumeToken();
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
9226 void Parser::SkipQualIdent() { 9235 void Parser::SkipQualIdent() {
9227 ASSERT(IsIdentifier()); 9236 ASSERT(IsIdentifier());
9228 ConsumeToken(); 9237 ConsumeToken();
9229 if (CurrentToken() == Token::kPERIOD) { 9238 if (CurrentToken() == Token::kPERIOD) {
9230 ConsumeToken(); // Consume the kPERIOD token. 9239 ConsumeToken(); // Consume the kPERIOD token.
9231 ExpectIdentifier("identifier expected after '.'"); 9240 ExpectIdentifier("identifier expected after '.'");
9232 } 9241 }
9233 } 9242 }
9234 9243
9235 } // namespace dart 9244 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698