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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart

Issue 1180973003: dart2js cps: Support function types in 'is' and 'as' operators. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update doc comment for TypeCast 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) 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 2315 matching lines...) Expand 10 before | Expand all | Expand 10 after
2326 }); 2326 });
2327 arguments = new List<ir.Primitive>.from(arguments) 2327 arguments = new List<ir.Primitive>.from(arguments)
2328 ..addAll(typeArguments); 2328 ..addAll(typeArguments);
2329 } 2329 }
2330 return _continueWithExpression( 2330 return _continueWithExpression(
2331 (k) => new ir.InvokeConstructor(type, element, selector, 2331 (k) => new ir.InvokeConstructor(type, element, selector,
2332 arguments, k)); 2332 arguments, k));
2333 } 2333 }
2334 2334
2335 ir.Primitive buildTypeExpression(DartType type) { 2335 ir.Primitive buildTypeExpression(DartType type) {
2336 type = program.unaliasType(type);
2336 if (type is TypeVariableType) { 2337 if (type is TypeVariableType) {
2337 return buildTypeVariableAccess(type); 2338 return buildTypeVariableAccess(type);
2338 } else if (type is InterfaceType) { 2339 } else if (type is InterfaceType || type is FunctionType) {
2339 List<ir.Primitive> arguments = <ir.Primitive>[]; 2340 List<ir.Primitive> arguments = <ir.Primitive>[];
2340 type.forEachTypeVariable((TypeVariableType variable) { 2341 type.forEachTypeVariable((TypeVariableType variable) {
2341 ir.Primitive value = buildTypeVariableAccess(variable); 2342 ir.Primitive value = buildTypeVariableAccess(variable);
2342 arguments.add(value); 2343 arguments.add(value);
2343 }); 2344 });
2344 return addPrimitive(new ir.TypeExpression(type, arguments)); 2345 return addPrimitive(new ir.TypeExpression(type, arguments));
2345 } else if (type.treatAsDynamic) { 2346 } else if (type.treatAsDynamic) {
2346 return buildNullConstant(); 2347 return buildNullConstant();
2347 } else { 2348 } else {
2348 // TypedefType can reach here, and possibly other things. 2349 // TypedefType can reach here, and possibly other things.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments)); 2391 return addPrimitive(new ir.CreateInvocationMirror(selector, arguments));
2391 } 2392 }
2392 2393
2393 @override 2394 @override
2394 ir.Primitive buildTypeOperator(ir.Primitive value, 2395 ir.Primitive buildTypeOperator(ir.Primitive value,
2395 DartType type, 2396 DartType type,
2396 {bool isTypeTest}) { 2397 {bool isTypeTest}) {
2397 assert(isOpen); 2398 assert(isOpen);
2398 assert(isTypeTest != null); 2399 assert(isTypeTest != null);
2399 2400
2401 type = program.unaliasType(type);
2402
2400 if (type.isMalformed) { 2403 if (type.isMalformed) {
2401 FunctionElement helper = program.throwTypeErrorHelper; 2404 FunctionElement helper = program.throwTypeErrorHelper;
2402 ErroneousElement element = type.element; 2405 ErroneousElement element = type.element;
2403 ir.Primitive message = buildStringConstant(element.message); 2406 ir.Primitive message = buildStringConstant(element.message);
2404 return buildStaticFunctionInvocation( 2407 return buildStaticFunctionInvocation(
2405 helper, 2408 helper,
2406 CallStructure.ONE_ARG, 2409 CallStructure.ONE_ARG,
2407 <ir.Primitive>[message]); 2410 <ir.Primitive>[message]);
2408 } 2411 }
2409 2412
2410 List<ir.Primitive> typeArguments = const <ir.Primitive>[]; 2413 List<ir.Primitive> typeArguments = const <ir.Primitive>[];
2411 if (type is GenericType && type.typeArguments.isNotEmpty) { 2414 if (type is GenericType && type.typeArguments.isNotEmpty) {
2412 typeArguments = type.typeArguments.map(buildTypeExpression).toList(); 2415 typeArguments = type.typeArguments.map(buildTypeExpression).toList();
2413 } else if (type is TypeVariableType) { 2416 } else if (type is TypeVariableType) {
2414 typeArguments = <ir.Primitive>[buildTypeVariableAccess(type)]; 2417 typeArguments = <ir.Primitive>[buildTypeVariableAccess(type)];
2418 } else if (type is FunctionType) {
2419 typeArguments = <ir.Primitive>[buildTypeExpression(type)];
2415 } 2420 }
2416 2421
2417 if (isTypeTest) { 2422 if (isTypeTest) {
2418 // For type tests, we must treat specially the rare cases where `null` 2423 // For type tests, we must treat specially the rare cases where `null`
2419 // satisfies the test (which otherwise never satisfies a type test). 2424 // satisfies the test (which otherwise never satisfies a type test).
2420 // This is not an optimization: the TypeOperator assumes that `null` 2425 // This is not an optimization: the TypeOperator assumes that `null`
2421 // cannot satisfy the type test unless the type is a type variable. 2426 // cannot satisfy the type test unless the type is a type variable.
2422 if (type.isObject || type.isDynamic) { 2427 if (type.isObject || type.isDynamic) {
2423 // `x is Object` and `x is dynamic` are always true, even if x is null. 2428 // `x is Object` and `x is dynamic` are always true, even if x is null.
2424 return buildBooleanConstant(true); 2429 return buildBooleanConstant(true);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 final DartType type; 2524 final DartType type;
2520 final LocalVariableElement exceptionVariable; 2525 final LocalVariableElement exceptionVariable;
2521 final LocalVariableElement stackTraceVariable; 2526 final LocalVariableElement stackTraceVariable;
2522 final SubbuildFunction buildCatchBlock; 2527 final SubbuildFunction buildCatchBlock;
2523 2528
2524 CatchClauseInfo({this.type, 2529 CatchClauseInfo({this.type,
2525 this.exceptionVariable, 2530 this.exceptionVariable,
2526 this.stackTraceVariable, 2531 this.stackTraceVariable,
2527 this.buildCatchBlock}); 2532 this.buildCatchBlock});
2528 } 2533 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/compiler.dart ('k') | 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