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

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

Issue 9664029: Fix type check to perform a subtype test at top level instead of an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « runtime/vm/object.cc ('k') | tests/co19/co19-runtime.status » ('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 7069 matching lines...) Expand 10 before | Expand all | Expand 10 after
7080 AstNode* element = ParseExpr(is_const); 7080 AstNode* element = ParseExpr(is_const);
7081 if (FLAG_enable_type_checks && 7081 if (FLAG_enable_type_checks &&
7082 !is_const && 7082 !is_const &&
7083 !element_type.IsDynamicType()) { 7083 !element_type.IsDynamicType()) {
7084 // The expression needs to be type checked at runtime. 7084 // The expression needs to be type checked at runtime.
7085 // Eliminate the type check if it can be performed at compile time and 7085 // Eliminate the type check if it can be performed at compile time and
7086 // if it succeeds. 7086 // if it succeeds.
7087 Error& malformed_error = Error::Handle(); 7087 Error& malformed_error = Error::Handle();
7088 if (!element_type.IsInstantiated() || 7088 if (!element_type.IsInstantiated() ||
7089 !element->IsLiteralNode() || 7089 !element->IsLiteralNode() ||
7090 !element->AsLiteralNode()->literal(). 7090 (!element->AsLiteralNode()->literal().IsNull() &&
7091 IsAssignableTo(element_type, 7091 !element->AsLiteralNode()->literal().IsInstanceOf(
7092 TypeArguments::Handle(), 7092 element_type,
7093 &malformed_error)) { 7093 TypeArguments::Handle(),
7094 &malformed_error))) {
7094 element = new AssignableNode(element_pos, 7095 element = new AssignableNode(element_pos,
7095 element, 7096 element,
7096 element_type, 7097 element_type,
7097 dst_name); 7098 dst_name);
7098 } 7099 }
7099 } 7100 }
7100 list->AddElement(element); 7101 list->AddElement(element);
7101 if (CurrentToken() == Token::kCOMMA) { 7102 if (CurrentToken() == Token::kCOMMA) {
7102 ConsumeToken(); 7103 ConsumeToken();
7103 } else if (CurrentToken() != Token::kRBRACK) { 7104 } else if (CurrentToken() != Token::kRBRACK) {
7104 ErrorMsg("comma or ']' expected"); 7105 ErrorMsg("comma or ']' expected");
7105 } 7106 }
7106 } 7107 }
7107 ExpectToken(Token::kRBRACK); 7108 ExpectToken(Token::kRBRACK);
7108 SetAllowFunctionLiterals(saved_mode); 7109 SetAllowFunctionLiterals(saved_mode);
7109 } 7110 }
7110 7111
7111 if (is_const) { 7112 if (is_const) {
7112 // Allocate and initialize the const list at compile time. 7113 // Allocate and initialize the const list at compile time.
7113 Array& const_list = 7114 Array& const_list =
7114 Array::ZoneHandle(Array::New(list->length(), Heap::kOld)); 7115 Array::ZoneHandle(Array::New(list->length(), Heap::kOld));
7115 const_list.SetTypeArguments(type_arguments); 7116 const_list.SetTypeArguments(type_arguments);
7116 Error& malformed_error = Error::Handle(); 7117 Error& malformed_error = Error::Handle();
7117 for (int i = 0; i < list->length(); i++) { 7118 for (int i = 0; i < list->length(); i++) {
7118 AstNode* elem = list->ElementAt(i); 7119 AstNode* elem = list->ElementAt(i);
7119 // Arguments have been evaluated to a literal value already. 7120 // Arguments have been evaluated to a literal value already.
7120 ASSERT(elem->IsLiteralNode()); 7121 ASSERT(elem->IsLiteralNode());
7121 if (FLAG_enable_type_checks && 7122 if (FLAG_enable_type_checks &&
7122 !element_type.IsDynamicType() && 7123 !element_type.IsDynamicType() &&
7123 !elem->AsLiteralNode()->literal().IsAssignableTo( 7124 (!elem->AsLiteralNode()->literal().IsNull() &&
7124 element_type, TypeArguments::Handle(), &malformed_error)) { 7125 !elem->AsLiteralNode()->literal().IsInstanceOf(
7126 element_type, TypeArguments::Handle(), &malformed_error))) {
7125 // If the failure is due to a malformed type error, display it instead. 7127 // If the failure is due to a malformed type error, display it instead.
7126 if (!malformed_error.IsNull()) { 7128 if (!malformed_error.IsNull()) {
7127 ErrorMsg(malformed_error); 7129 ErrorMsg(malformed_error);
7128 } else { 7130 } else {
7129 ErrorMsg(elem->AsLiteralNode()->token_index(), 7131 ErrorMsg(elem->AsLiteralNode()->token_index(),
7130 "list literal element at index %d must be " 7132 "list literal element at index %d must be "
7131 "a constant of type '%s'", 7133 "a constant of type '%s'",
7132 i, 7134 i,
7133 String::Handle(element_type.Name()).ToCString()); 7135 String::Handle(element_type.Name()).ToCString());
7134 } 7136 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
7265 SetAllowFunctionLiterals(saved_mode); 7267 SetAllowFunctionLiterals(saved_mode);
7266 if (FLAG_enable_type_checks && 7268 if (FLAG_enable_type_checks &&
7267 !is_const && 7269 !is_const &&
7268 !value_type.IsDynamicType()) { 7270 !value_type.IsDynamicType()) {
7269 // The expression needs to be type checked at runtime. 7271 // The expression needs to be type checked at runtime.
7270 // Eliminate the type check if it can be performed at compile time and 7272 // Eliminate the type check if it can be performed at compile time and
7271 // if it succeeds. 7273 // if it succeeds.
7272 Error& malformed_error = Error::Handle(); 7274 Error& malformed_error = Error::Handle();
7273 if (!value_type.IsInstantiated() || 7275 if (!value_type.IsInstantiated() ||
7274 !value->IsLiteralNode() || 7276 !value->IsLiteralNode() ||
7275 !value->AsLiteralNode()->literal().IsAssignableTo( 7277 (!value->AsLiteralNode()->literal().IsNull() &&
7276 value_type, TypeArguments::Handle(), &malformed_error)) { 7278 !value->AsLiteralNode()->literal().IsInstanceOf(
7279 value_type, TypeArguments::Handle(), &malformed_error))) {
7277 value = new AssignableNode(value_pos, 7280 value = new AssignableNode(value_pos,
7278 value, 7281 value,
7279 value_type, 7282 value_type,
7280 dst_name); 7283 dst_name);
7281 } 7284 }
7282 } 7285 }
7283 AddKeyValuePair(kv_pairs, is_const, key, value); 7286 AddKeyValuePair(kv_pairs, is_const, key, value);
7284 7287
7285 if (CurrentToken() == Token::kCOMMA) { 7288 if (CurrentToken() == Token::kCOMMA) {
7286 ConsumeToken(); 7289 ConsumeToken();
(...skipping 13 matching lines...) Expand all
7300 Array& key_value_array = 7303 Array& key_value_array =
7301 Array::ZoneHandle(Array::New(kv_pairs->length(), Heap::kOld)); 7304 Array::ZoneHandle(Array::New(kv_pairs->length(), Heap::kOld));
7302 Error& malformed_error = Error::Handle(); 7305 Error& malformed_error = Error::Handle();
7303 for (int i = 0; i < kv_pairs->length(); i++) { 7306 for (int i = 0; i < kv_pairs->length(); i++) {
7304 AstNode* arg = kv_pairs->ElementAt(i); 7307 AstNode* arg = kv_pairs->ElementAt(i);
7305 // Arguments have been evaluated to a literal value already. 7308 // Arguments have been evaluated to a literal value already.
7306 ASSERT(arg->IsLiteralNode()); 7309 ASSERT(arg->IsLiteralNode());
7307 if (FLAG_enable_type_checks && 7310 if (FLAG_enable_type_checks &&
7308 ((i % 2) == 1) && // Check values only, not keys. 7311 ((i % 2) == 1) && // Check values only, not keys.
7309 !value_type.IsDynamicType() && 7312 !value_type.IsDynamicType() &&
7310 !arg->AsLiteralNode()->literal().IsAssignableTo( 7313 (!arg->AsLiteralNode()->literal().IsNull() &&
7311 value_type, TypeArguments::Handle(), &malformed_error)) { 7314 !arg->AsLiteralNode()->literal().IsInstanceOf(
7315 value_type, TypeArguments::Handle(), &malformed_error))) {
7312 // If the failure is due to a malformed type error, display it instead. 7316 // If the failure is due to a malformed type error, display it instead.
7313 if (!malformed_error.IsNull()) { 7317 if (!malformed_error.IsNull()) {
7314 ErrorMsg(malformed_error); 7318 ErrorMsg(malformed_error);
7315 } else { 7319 } else {
7316 ErrorMsg(arg->AsLiteralNode()->token_index(), 7320 ErrorMsg(arg->AsLiteralNode()->token_index(),
7317 "map literal value at index %d must be " 7321 "map literal value at index %d must be "
7318 "a constant of type '%s'", 7322 "a constant of type '%s'",
7319 i >> 1, 7323 i >> 1,
7320 String::Handle(value_type.Name()).ToCString()); 7324 String::Handle(value_type.Name()).ToCString());
7321 } 7325 }
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
8203 void Parser::SkipQualIdent() { 8207 void Parser::SkipQualIdent() {
8204 ASSERT(IsIdentifier()); 8208 ASSERT(IsIdentifier());
8205 ConsumeToken(); 8209 ConsumeToken();
8206 if (CurrentToken() == Token::kPERIOD) { 8210 if (CurrentToken() == Token::kPERIOD) {
8207 ConsumeToken(); // Consume the kPERIOD token. 8211 ConsumeToken(); // Consume the kPERIOD token.
8208 ExpectIdentifier("identifier expected after '.'"); 8212 ExpectIdentifier("identifier expected after '.'");
8209 } 8213 }
8210 } 8214 }
8211 8215
8212 } // namespace dart 8216 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698