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

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

Issue 27420002: Throw a dynamic type error instead of a CastError in a type cast with a (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | « no previous file | runtime/vm/parser.cc » ('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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/bit_vector.h" 9 #include "vm/bit_vector.h"
10 #include "vm/code_descriptors.h" 10 #include "vm/code_descriptors.h"
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 Object::null_array(), // No argument names. 1291 Object::null_array(), // No argument names.
1292 kNumArgsChecked, 1292 kNumArgsChecked,
1293 owner()->ic_data_array()); 1293 owner()->ic_data_array());
1294 ReturnDefinition(call); 1294 ReturnDefinition(call);
1295 } 1295 }
1296 1296
1297 1297
1298 void EffectGraphVisitor::BuildTypeCast(ComparisonNode* node) { 1298 void EffectGraphVisitor::BuildTypeCast(ComparisonNode* node) {
1299 ASSERT(Token::IsTypeCastOperator(node->kind())); 1299 ASSERT(Token::IsTypeCastOperator(node->kind()));
1300 const AbstractType& type = node->right()->AsTypeNode()->type(); 1300 const AbstractType& type = node->right()->AsTypeNode()->type();
1301 ASSERT(type.IsFinalized()); // The type in a type cast may be malformed. 1301 ASSERT(type.IsFinalized() && !type.IsMalformed() && !type.IsMalbounded());
1302 ValueGraphVisitor for_value(owner(), temp_index()); 1302 ValueGraphVisitor for_value(owner(), temp_index());
1303 node->left()->Visit(&for_value); 1303 node->left()->Visit(&for_value);
1304 const String& dst_name = String::ZoneHandle( 1304 const String& dst_name = String::ZoneHandle(
1305 Symbols::New(Exceptions::kCastErrorDstName)); 1305 Symbols::New(Exceptions::kCastErrorDstName));
1306 if (!CanSkipTypeCheck(node->token_pos(), for_value.value(), type, dst_name)) { 1306 if (!CanSkipTypeCheck(node->token_pos(), for_value.value(), type, dst_name)) {
1307 Append(for_value); 1307 Append(for_value);
1308 Do(BuildAssertAssignable( 1308 Do(BuildAssertAssignable(
1309 node->token_pos(), for_value.value(), type, dst_name)); 1309 node->token_pos(), for_value.value(), type, dst_name));
1310 } 1310 }
1311 } 1311 }
1312 1312
1313 1313
1314 void ValueGraphVisitor::BuildTypeCast(ComparisonNode* node) { 1314 void ValueGraphVisitor::BuildTypeCast(ComparisonNode* node) {
1315 ASSERT(Token::IsTypeCastOperator(node->kind())); 1315 ASSERT(Token::IsTypeCastOperator(node->kind()));
1316 ASSERT(!node->right()->AsTypeNode()->type().IsNull()); 1316 ASSERT(!node->right()->AsTypeNode()->type().IsNull());
1317 const AbstractType& type = node->right()->AsTypeNode()->type(); 1317 const AbstractType& type = node->right()->AsTypeNode()->type();
1318 ASSERT(type.IsFinalized()); // The type in a type cast may be malformed. 1318 ASSERT(type.IsFinalized() && !type.IsMalformed() && !type.IsMalbounded());
1319 ValueGraphVisitor for_value(owner(), temp_index()); 1319 ValueGraphVisitor for_value(owner(), temp_index());
1320 node->left()->Visit(&for_value); 1320 node->left()->Visit(&for_value);
1321 Append(for_value); 1321 Append(for_value);
1322 const String& dst_name = String::ZoneHandle( 1322 const String& dst_name = String::ZoneHandle(
1323 Symbols::New(Exceptions::kCastErrorDstName)); 1323 Symbols::New(Exceptions::kCastErrorDstName));
1324 if (type.IsMalformed() || type.IsMalbounded()) { 1324 if (CanSkipTypeCheck(node->token_pos(),
1325 ReturnValue(BuildAssignableValue(node->token_pos(), 1325 for_value.value(),
1326 for_value.value(), 1326 type,
1327 type, 1327 dst_name)) {
1328 dst_name)); 1328 ReturnValue(for_value.value());
1329 return;
1330 }
1331 PushArgumentInstr* push_left = PushArgument(for_value.value());
1332 PushArgumentInstr* push_instantiator = NULL;
1333 PushArgumentInstr* push_type_args = NULL;
1334 if (type.IsInstantiated()) {
1335 push_instantiator = PushArgument(BuildNullValue());
1336 push_type_args = PushArgument(BuildNullValue());
1329 } else { 1337 } else {
1330 if (CanSkipTypeCheck(node->token_pos(), 1338 BuildTypecheckPushArguments(node->token_pos(),
1331 for_value.value(), 1339 &push_instantiator,
1332 type, 1340 &push_type_args);
1333 dst_name)) {
1334 ReturnValue(for_value.value());
1335 return;
1336 }
1337 PushArgumentInstr* push_left = PushArgument(for_value.value());
1338 PushArgumentInstr* push_instantiator = NULL;
1339 PushArgumentInstr* push_type_args = NULL;
1340 if (type.IsInstantiated()) {
1341 push_instantiator = PushArgument(BuildNullValue());
1342 push_type_args = PushArgument(BuildNullValue());
1343 } else {
1344 BuildTypecheckPushArguments(node->token_pos(),
1345 &push_instantiator,
1346 &push_type_args);
1347 }
1348 ZoneGrowableArray<PushArgumentInstr*>* arguments =
1349 new ZoneGrowableArray<PushArgumentInstr*>(4);
1350 arguments->Add(push_left);
1351 arguments->Add(push_instantiator);
1352 arguments->Add(push_type_args);
1353 Value* type_arg = Bind(new ConstantInstr(type));
1354 arguments->Add(PushArgument(type_arg));
1355 const intptr_t kNumArgsChecked = 1;
1356 InstanceCallInstr* call = new InstanceCallInstr(
1357 node->token_pos(),
1358 Library::PrivateCoreLibName(Symbols::_as()),
1359 node->kind(),
1360 arguments,
1361 Object::null_array(), // No argument names.
1362 kNumArgsChecked,
1363 owner()->ic_data_array());
1364 ReturnDefinition(call);
1365 } 1341 }
1342 ZoneGrowableArray<PushArgumentInstr*>* arguments =
1343 new ZoneGrowableArray<PushArgumentInstr*>(4);
1344 arguments->Add(push_left);
1345 arguments->Add(push_instantiator);
1346 arguments->Add(push_type_args);
1347 Value* type_arg = Bind(new ConstantInstr(type));
1348 arguments->Add(PushArgument(type_arg));
1349 const intptr_t kNumArgsChecked = 1;
1350 InstanceCallInstr* call = new InstanceCallInstr(
1351 node->token_pos(),
1352 Library::PrivateCoreLibName(Symbols::_as()),
1353 node->kind(),
1354 arguments,
1355 Object::null_array(), // No argument names.
1356 kNumArgsChecked,
1357 owner()->ic_data_array());
1358 ReturnDefinition(call);
1366 } 1359 }
1367 1360
1368 1361
1369 // <Expression> :: Comparison { kind: Token::Kind 1362 // <Expression> :: Comparison { kind: Token::Kind
1370 // left: <Expression> 1363 // left: <Expression>
1371 // right: <Expression> } 1364 // right: <Expression> }
1372 // TODO(srdjan): Implement new equality. 1365 // TODO(srdjan): Implement new equality.
1373 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) { 1366 void EffectGraphVisitor::VisitComparisonNode(ComparisonNode* node) {
1374 if (Token::IsTypeTestOperator(node->kind())) { 1367 if (Token::IsTypeTestOperator(node->kind())) {
1375 BuildTypeTest(node); 1368 BuildTypeTest(node);
(...skipping 2463 matching lines...) Expand 10 before | Expand all | Expand 10 after
3839 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 3832 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
3840 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 3833 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
3841 OS::SNPrint(chars, len, kFormat, function_name, reason); 3834 OS::SNPrint(chars, len, kFormat, function_name, reason);
3842 const Error& error = Error::Handle( 3835 const Error& error = Error::Handle(
3843 LanguageError::New(String::Handle(String::New(chars)))); 3836 LanguageError::New(String::Handle(String::New(chars))));
3844 Isolate::Current()->long_jump_base()->Jump(1, error); 3837 Isolate::Current()->long_jump_base()->Jump(1, error);
3845 } 3838 }
3846 3839
3847 3840
3848 } // namespace dart 3841 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698