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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1153603006: dart2js cps: Type casts and related changes to type propagation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Another typo in SExpression unstrngifier Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 348
349 @override 349 @override
350 js.Expression visitThis(tree_ir.This node) { 350 js.Expression visitThis(tree_ir.This node) {
351 return new js.This(); 351 return new js.This();
352 } 352 }
353 353
354 @override 354 @override
355 js.Expression visitTypeOperator(tree_ir.TypeOperator node) { 355 js.Expression visitTypeOperator(tree_ir.TypeOperator node) {
356 js.Expression value = visitExpression(node.value); 356 js.Expression value = visitExpression(node.value);
357 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments); 357 List<js.Expression> typeArguments = visitExpressionList(node.typeArguments);
358 if (!node.isTypeTest) {
359 giveup(node, 'type casts not implemented.');
360 }
361 DartType type = node.type; 358 DartType type = node.type;
362 // Note that the trivial (but special) cases of Object, dynamic, and Null
363 // are handled at build-time and must not occur in a TypeOperator.
364 assert(!type.isObject && !type.isDynamic);
365 if (type is InterfaceType) { 359 if (type is InterfaceType) {
366 glue.registerIsCheck(type, registry); 360 glue.registerIsCheck(type, registry);
367 ClassElement clazz = type.element; 361 ClassElement clazz = type.element;
368 362
369 // We use the helper: 363 // We use one of the two helpers:
370 // 364 //
371 // checkSubtype(value, $isT, typeArgs, $asT) 365 // checkSubtype(value, $isT, typeArgs, $asT)
366 // subtypeCast(value, $isT, typeArgs, $asT)
372 // 367 //
373 // Any of the last two arguments may be null if there are no type 368 // Any of the last two arguments may be null if there are no type
374 // arguments, and/or if no substitution is required. 369 // arguments, and/or if no substitution is required.
370 Element function = node.isTypeTest
371 ? glue.getCheckSubtype()
372 : glue.getSubtypeCast();
375 373
376 js.Expression isT = js.string(glue.getTypeTestTag(type)); 374 js.Expression isT = js.string(glue.getTypeTestTag(type));
377 375
378 js.Expression typeArgumentArray = typeArguments.isNotEmpty 376 js.Expression typeArgumentArray = typeArguments.isNotEmpty
379 ? new js.ArrayInitializer(typeArguments) 377 ? new js.ArrayInitializer(typeArguments)
380 : new js.LiteralNull(); 378 : new js.LiteralNull();
381 379
382 js.Expression asT = glue.hasStrictSubtype(clazz) 380 js.Expression asT = glue.hasStrictSubtype(clazz)
383 ? js.string(glue.getTypeSubstitutionTag(clazz)) 381 ? js.string(glue.getTypeSubstitutionTag(clazz))
384 : new js.LiteralNull(); 382 : new js.LiteralNull();
385 383
386 return buildStaticHelperInvocation( 384 return buildStaticHelperInvocation(
387 glue.getCheckSubtype(), 385 function,
388 <js.Expression>[value, isT, typeArgumentArray, asT]); 386 <js.Expression>[value, isT, typeArgumentArray, asT]);
389 } else if (type is TypeVariableType) { 387 } else if (type is TypeVariableType) {
390 glue.registerIsCheck(type, registry); 388 glue.registerIsCheck(type, registry);
389
390 Element function = node.isTypeTest
391 ? glue.getCheckSubtypeOfRuntimeType()
392 : glue.getSubtypeOfRuntimeTypeCast();
393
391 // The only type argument is the type held in the type variable. 394 // The only type argument is the type held in the type variable.
392 js.Expression typeValue = typeArguments.single; 395 js.Expression typeValue = typeArguments.single;
396
393 return buildStaticHelperInvocation( 397 return buildStaticHelperInvocation(
394 glue.getCheckSubtypeOfRuntime(), 398 function,
395 <js.Expression>[value, typeValue]); 399 <js.Expression>[value, typeValue]);
396 } 400 }
397 return giveup(node, 'type check unimplemented for $type.'); 401 return giveup(node, 'type check unimplemented for $type.');
398 } 402 }
399 403
400 @override 404 @override
401 js.Expression visitVariableUse(tree_ir.VariableUse node) { 405 js.Expression visitVariableUse(tree_ir.VariableUse node) {
402 return buildVariableAccess(node.variable); 406 return buildVariableAccess(node.variable);
403 } 407 }
404 408
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 void visitThrow(tree_ir.Throw node) { 544 void visitThrow(tree_ir.Throw node) {
541 accumulator.add(new js.Throw(visitExpression(node.value))); 545 accumulator.add(new js.Throw(visitExpression(node.value)));
542 } 546 }
543 547
544 @override 548 @override
545 void visitRethrow(tree_ir.Rethrow node) { 549 void visitRethrow(tree_ir.Rethrow node) {
546 glue.reportInternalError('rethrow seen in JavaScript output'); 550 glue.reportInternalError('rethrow seen in JavaScript output');
547 } 551 }
548 552
549 @override 553 @override
554 void visitUnreachable(tree_ir.Unreachable node) {
555 // Output nothing.
556 // TODO(asgerf): Emit a throw/return to assist local analysis in the VM?
557 }
558
559 @override
550 void visitTry(tree_ir.Try node) { 560 void visitTry(tree_ir.Try node) {
551 js.Block tryBlock = buildBodyBlock(node.tryBody); 561 js.Block tryBlock = buildBodyBlock(node.tryBody);
552 tree_ir.Variable exceptionVariable = node.catchParameters.first; 562 tree_ir.Variable exceptionVariable = node.catchParameters.first;
553 js.VariableDeclaration exceptionParameter = 563 js.VariableDeclaration exceptionParameter =
554 new js.VariableDeclaration(getVariableName(exceptionVariable)); 564 new js.VariableDeclaration(getVariableName(exceptionVariable));
555 js.Block catchBlock = buildBodyBlock(node.catchBody); 565 js.Block catchBlock = buildBodyBlock(node.catchBody);
556 js.Catch catchPart = new js.Catch(exceptionParameter, catchBlock); 566 js.Catch catchPart = new js.Catch(exceptionParameter, catchBlock);
557 accumulator.add(new js.Try(tryBlock, catchPart, null)); 567 accumulator.add(new js.Try(tryBlock, catchPart, null));
558 } 568 }
559 569
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 List<js.Expression> arguments = visitExpressionList(node.arguments); 694 List<js.Expression> arguments = visitExpressionList(node.arguments);
685 return glue.generateTypeRepresentation(node.dartType, arguments); 695 return glue.generateTypeRepresentation(node.dartType, arguments);
686 } 696 }
687 697
688 visitFunctionExpression(tree_ir.FunctionExpression node) { 698 visitFunctionExpression(tree_ir.FunctionExpression node) {
689 // FunctionExpressions are currently unused. 699 // FunctionExpressions are currently unused.
690 // We might need them if we want to emit raw JS nested functions. 700 // We might need them if we want to emit raw JS nested functions.
691 throw 'FunctionExpressions should not be used'; 701 throw 'FunctionExpressions should not be used';
692 } 702 }
693 } 703 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/glue.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698