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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import '../compile_time_constants.dart' show BackendConstantEnvironment; 7 import '../compile_time_constants.dart' show BackendConstantEnvironment;
8 import '../constants/constant_system.dart'; 8 import '../constants/constant_system.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; 10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue;
(...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 if (type.isMalformed) { 2400 if (type.isMalformed) {
2401 FunctionElement helper = program.throwTypeErrorHelper; 2401 FunctionElement helper = program.throwTypeErrorHelper;
2402 ErroneousElement element = type.element; 2402 ErroneousElement element = type.element;
2403 ir.Primitive message = buildStringConstant(element.message); 2403 ir.Primitive message = buildStringConstant(element.message);
2404 return buildStaticFunctionInvocation( 2404 return buildStaticFunctionInvocation(
2405 helper, 2405 helper,
2406 CallStructure.ONE_ARG, 2406 CallStructure.ONE_ARG,
2407 <ir.Primitive>[message]); 2407 <ir.Primitive>[message]);
2408 } 2408 }
2409 2409
2410 List<ir.Primitive> typeArguments = const <ir.Primitive>[];
2411 if (type is GenericType && type.typeArguments.isNotEmpty) {
2412 typeArguments = type.typeArguments.map(buildTypeExpression).toList();
2413 } else if (type is TypeVariableType) {
2414 typeArguments = <ir.Primitive>[buildTypeVariableAccess(type)];
2415 }
2416
2410 if (isTypeTest) { 2417 if (isTypeTest) {
2411 // For type tests, we must treat specially the rare cases where `null` 2418 // For type tests, we must treat specially the rare cases where `null`
2412 // satisfies the test (which otherwise never satisfies a type test). 2419 // satisfies the test (which otherwise never satisfies a type test).
2413 // This is not an optimization: the TypeOperator assumes that `null` 2420 // This is not an optimization: the TypeOperator assumes that `null`
2414 // cannot satisfy the type test. 2421 // cannot satisfy the type test unless the type is a type variable.
2415 if (type.isObject || type.isDynamic) { 2422 if (type.isObject || type.isDynamic) {
2416 // `x is Object` and `x is dynamic` are always true, even if x is null. 2423 // `x is Object` and `x is dynamic` are always true, even if x is null.
2417 return buildBooleanConstant(true); 2424 return buildBooleanConstant(true);
2418 } 2425 }
2419 if (type is InterfaceType && type.element == program.nullClass) { 2426 if (type is InterfaceType && type.element == program.nullClass) {
2420 // `x is Null` is true if and only if x is null. 2427 // `x is Null` is true if and only if x is null.
2421 return addPrimitive(new ir.Identical(value, buildNullConstant())); 2428 return addPrimitive(new ir.Identical(value, buildNullConstant()));
2422 } 2429 }
2430 return addPrimitive(new ir.TypeTest(value, type, typeArguments));
2431 } else {
2432 return _continueWithExpression(
2433 (k) => new ir.TypeCast(value, type, typeArguments, k));
2423 } 2434 }
2424 List<ir.Primitive> typeArguments = const <ir.Primitive>[];
2425 if (type is GenericType && type.typeArguments.isNotEmpty) {
2426 typeArguments = type.typeArguments.map(buildTypeExpression).toList();
2427 } else if (type is TypeVariableType) {
2428 typeArguments = <ir.Primitive>[buildTypeVariableAccess(type)];
2429 }
2430 ir.Primitive check = _continueWithExpression(
2431 (k) => new ir.TypeOperator(value,
2432 type, typeArguments, k, isTypeTest: isTypeTest));
2433 return check;
2434 } 2435 }
2435 2436
2436 @override 2437 @override
2437 ir.Primitive buildIfNull(ir.Primitive value, 2438 ir.Primitive buildIfNull(ir.Primitive value,
2438 ir.Primitive buildRight(IrBuilder builder)) { 2439 ir.Primitive buildRight(IrBuilder builder)) {
2439 ir.Primitive condition = _buildCheckNull(value); 2440 ir.Primitive condition = _buildCheckNull(value);
2440 return buildConditional(condition, buildRight, (_) => value); 2441 return buildConditional(condition, buildRight, (_) => value);
2441 } 2442 }
2442 2443
2443 @override 2444 @override
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 final DartType type; 2519 final DartType type;
2519 final LocalVariableElement exceptionVariable; 2520 final LocalVariableElement exceptionVariable;
2520 final LocalVariableElement stackTraceVariable; 2521 final LocalVariableElement stackTraceVariable;
2521 final SubbuildFunction buildCatchBlock; 2522 final SubbuildFunction buildCatchBlock;
2522 2523
2523 CatchClauseInfo({this.type, 2524 CatchClauseInfo({this.type,
2524 this.exceptionVariable, 2525 this.exceptionVariable,
2525 this.stackTraceVariable, 2526 this.stackTraceVariable,
2526 this.buildCatchBlock}); 2527 this.buildCatchBlock});
2527 } 2528 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698