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

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

Issue 2616653003: Use elements/types.dart in codegen.dart (Closed)
Patch Set: dartfmt Created 3 years, 11 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) 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 import 'dart:math' as math; 5 import 'dart:math' as math;
6 import '../common.dart'; 6 import '../common.dart';
7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; 7 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem;
8 import '../common/tasks.dart' show CompilerTask; 8 import '../common/tasks.dart' show CompilerTask;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constant_system.dart'; 10 import '../constants/constant_system.dart';
11 import '../constants/values.dart'; 11 import '../constants/values.dart';
12 import '../core_types.dart' show CommonElements; 12 import '../core_types.dart' show CommonElements;
13 import '../elements/elements.dart' 13 import '../elements/elements.dart'
14 show 14 show
15 Entity, 15 Entity,
16 JumpTarget, 16 JumpTarget,
17 LabelDefinition, 17 LabelDefinition,
18 Local, 18 Local,
19 Name, 19 Name,
20 AsyncMarker, 20 AsyncMarker,
21 ResolvedAst, 21 ResolvedAst,
22 FunctionElement; 22 FunctionElement;
23 import '../elements/entities.dart'; 23 import '../elements/entities.dart';
24 import '../elements/resolution_types.dart'; 24 import '../elements/types.dart';
25 import '../io/source_information.dart'; 25 import '../io/source_information.dart';
26 import '../js/js.dart' as js; 26 import '../js/js.dart' as js;
27 import '../js_backend/backend_helpers.dart' show BackendHelpers; 27 import '../js_backend/backend_helpers.dart' show BackendHelpers;
28 import '../js_backend/js_backend.dart'; 28 import '../js_backend/js_backend.dart';
29 import '../js_emitter/js_emitter.dart' show NativeEmitter; 29 import '../js_emitter/js_emitter.dart' show NativeEmitter;
30 import '../native/native.dart' as native; 30 import '../native/native.dart' as native;
31 import '../types/types.dart'; 31 import '../types/types.dart';
32 import '../universe/call_structure.dart' show CallStructure; 32 import '../universe/call_structure.dart' show CallStructure;
33 import '../universe/selector.dart' show Selector; 33 import '../universe/selector.dart' show Selector;
34 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; 34 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse;
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 new js.PropertyAccess(pop(), backend.namer.operatorIsType(type)) 2622 new js.PropertyAccess(pop(), backend.namer.operatorIsType(type))
2623 .withSourceInformation(sourceInformation); 2623 .withSourceInformation(sourceInformation);
2624 // We always negate at least once so that the result is boolified. 2624 // We always negate at least once so that the result is boolified.
2625 push(new js.Prefix('!', field).withSourceInformation(sourceInformation)); 2625 push(new js.Prefix('!', field).withSourceInformation(sourceInformation));
2626 // If the result is not negated, put another '!' in front. 2626 // If the result is not negated, put another '!' in front.
2627 if (!negative) { 2627 if (!negative) {
2628 push(new js.Prefix('!', pop()).withSourceInformation(sourceInformation)); 2628 push(new js.Prefix('!', pop()).withSourceInformation(sourceInformation));
2629 } 2629 }
2630 } 2630 }
2631 2631
2632 void checkTypeViaInstanceof( 2632 void checkTypeViaInstanceof(HInstruction input, InterfaceType type,
2633 HInstruction input, DartType type, SourceInformation sourceInformation, 2633 SourceInformation sourceInformation,
2634 {bool negative: false}) { 2634 {bool negative: false}) {
2635 registry.registerTypeUse(new TypeUse.isCheck(type)); 2635 registry.registerTypeUse(new TypeUse.isCheck(type));
2636 2636
2637 use(input); 2637 use(input);
2638 2638
2639 js.Expression jsClassReference = 2639 js.Expression jsClassReference =
2640 backend.emitter.constructorAccess(type.element); 2640 backend.emitter.constructorAccess(type.element);
2641 push(js.js('# instanceof #', 2641 push(js.js('# instanceof #',
2642 [pop(), jsClassReference]).withSourceInformation(sourceInformation)); 2642 [pop(), jsClassReference]).withSourceInformation(sourceInformation));
2643 if (negative) { 2643 if (negative) {
2644 push(new js.Prefix('!', pop()).withSourceInformation(sourceInformation)); 2644 push(new js.Prefix('!', pop()).withSourceInformation(sourceInformation));
2645 } 2645 }
2646 registry.registerInstantiation(type); 2646 registry.registerInstantiation(type);
2647 } 2647 }
2648 2648
2649 void handleNumberOrStringSupertypeCheck( 2649 void handleNumberOrStringSupertypeCheck(
2650 HInstruction input, 2650 HInstruction input,
2651 HInstruction interceptor, 2651 HInstruction interceptor,
2652 DartType type, 2652 InterfaceType type,
2653 SourceInformation sourceInformation, 2653 SourceInformation sourceInformation,
2654 {bool negative: false}) { 2654 {bool negative: false}) {
2655 assert(!identical(type.element, commonElements.listClass) && 2655 assert(!identical(type.element, commonElements.listClass) &&
2656 !commonElements.isListSupertype(type.element) && 2656 !commonElements.isListSupertype(type.element) &&
2657 !commonElements.isStringOnlySupertype(type.element)); 2657 !commonElements.isStringOnlySupertype(type.element));
2658 String relation = negative ? '!==' : '==='; 2658 String relation = negative ? '!==' : '===';
2659 checkNum(input, relation, sourceInformation); 2659 checkNum(input, relation, sourceInformation);
2660 js.Expression numberTest = pop(); 2660 js.Expression numberTest = pop();
2661 checkString(input, relation, sourceInformation); 2661 checkString(input, relation, sourceInformation);
2662 js.Expression stringTest = pop(); 2662 js.Expression stringTest = pop();
2663 checkObject(input, relation, sourceInformation); 2663 checkObject(input, relation, sourceInformation);
2664 js.Expression objectTest = pop(); 2664 js.Expression objectTest = pop();
2665 checkType(input, interceptor, type, sourceInformation, negative: negative); 2665 checkType(input, interceptor, type, sourceInformation, negative: negative);
2666 String combiner = negative ? '&&' : '||'; 2666 String combiner = negative ? '&&' : '||';
2667 String combiner2 = negative ? '||' : '&&'; 2667 String combiner2 = negative ? '||' : '&&';
2668 push(new js.Binary( 2668 push(new js.Binary(
2669 combiner, 2669 combiner,
2670 new js.Binary(combiner, numberTest, stringTest) 2670 new js.Binary(combiner, numberTest, stringTest)
2671 .withSourceInformation(sourceInformation), 2671 .withSourceInformation(sourceInformation),
2672 new js.Binary(combiner2, objectTest, pop()) 2672 new js.Binary(combiner2, objectTest, pop())
2673 .withSourceInformation(sourceInformation)) 2673 .withSourceInformation(sourceInformation))
2674 .withSourceInformation(sourceInformation)); 2674 .withSourceInformation(sourceInformation));
2675 } 2675 }
2676 2676
2677 void handleStringSupertypeCheck(HInstruction input, HInstruction interceptor, 2677 void handleStringSupertypeCheck(HInstruction input, HInstruction interceptor,
2678 DartType type, SourceInformation sourceInformation, 2678 InterfaceType type, SourceInformation sourceInformation,
2679 {bool negative: false}) { 2679 {bool negative: false}) {
2680 assert(!identical(type.element, commonElements.listClass) && 2680 assert(!identical(type.element, commonElements.listClass) &&
2681 !commonElements.isListSupertype(type.element) && 2681 !commonElements.isListSupertype(type.element) &&
2682 !commonElements.isNumberOrStringSupertype(type.element)); 2682 !commonElements.isNumberOrStringSupertype(type.element));
2683 String relation = negative ? '!==' : '==='; 2683 String relation = negative ? '!==' : '===';
2684 checkString(input, relation, sourceInformation); 2684 checkString(input, relation, sourceInformation);
2685 js.Expression stringTest = pop(); 2685 js.Expression stringTest = pop();
2686 checkObject(input, relation, sourceInformation); 2686 checkObject(input, relation, sourceInformation);
2687 js.Expression objectTest = pop(); 2687 js.Expression objectTest = pop();
2688 checkType(input, interceptor, type, sourceInformation, negative: negative); 2688 checkType(input, interceptor, type, sourceInformation, negative: negative);
2689 String combiner = negative ? '||' : '&&'; 2689 String combiner = negative ? '||' : '&&';
2690 push(new js.Binary(negative ? '&&' : '||', stringTest, 2690 push(new js.Binary(negative ? '&&' : '||', stringTest,
2691 new js.Binary(combiner, objectTest, pop()))); 2691 new js.Binary(combiner, objectTest, pop())));
2692 } 2692 }
2693 2693
2694 void handleListOrSupertypeCheck(HInstruction input, HInstruction interceptor, 2694 void handleListOrSupertypeCheck(HInstruction input, HInstruction interceptor,
2695 DartType type, SourceInformation sourceInformation, 2695 InterfaceType type, SourceInformation sourceInformation,
2696 {bool negative: false}) { 2696 {bool negative: false}) {
2697 assert(!identical(type.element, commonElements.stringClass) && 2697 assert(!identical(type.element, commonElements.stringClass) &&
2698 !commonElements.isStringOnlySupertype(type.element) && 2698 !commonElements.isStringOnlySupertype(type.element) &&
2699 !commonElements.isNumberOrStringSupertype(type.element)); 2699 !commonElements.isNumberOrStringSupertype(type.element));
2700 String relation = negative ? '!==' : '==='; 2700 String relation = negative ? '!==' : '===';
2701 checkObject(input, relation, sourceInformation); 2701 checkObject(input, relation, sourceInformation);
2702 js.Expression objectTest = pop(); 2702 js.Expression objectTest = pop();
2703 checkArray(input, relation); 2703 checkArray(input, relation);
2704 js.Expression arrayTest = pop(); 2704 js.Expression arrayTest = pop();
2705 checkType(input, interceptor, type, sourceInformation, negative: negative); 2705 checkType(input, interceptor, type, sourceInformation, negative: negative);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 case TypeInfoExpressionKind.COMPLETE: 3011 case TypeInfoExpressionKind.COMPLETE:
3012 int index = 0; 3012 int index = 0;
3013 js.Expression result = backend.rtiEncoder.getTypeRepresentation( 3013 js.Expression result = backend.rtiEncoder.getTypeRepresentation(
3014 node.dartType, (TypeVariableType variable) => arguments[index++]); 3014 node.dartType, (TypeVariableType variable) => arguments[index++]);
3015 assert(index == node.inputs.length); 3015 assert(index == node.inputs.length);
3016 push(result); 3016 push(result);
3017 return; 3017 return;
3018 3018
3019 case TypeInfoExpressionKind.INSTANCE: 3019 case TypeInfoExpressionKind.INSTANCE:
3020 // We expect only flat types for the INSTANCE representation. 3020 // We expect only flat types for the INSTANCE representation.
3021 assert( 3021 assert((node.dartType as InterfaceType).typeArguments.length ==
3022 node.dartType == (node.dartType as InterfaceType).element.thisType); 3022 arguments.length);
3023 registry.registerInstantiatedClass(commonElements.listClass); 3023 registry.registerInstantiatedClass(commonElements.listClass);
3024 push(new js.ArrayInitializer(arguments) 3024 push(new js.ArrayInitializer(arguments)
3025 .withSourceInformation(node.sourceInformation)); 3025 .withSourceInformation(node.sourceInformation));
3026 } 3026 }
3027 } 3027 }
3028 3028
3029 bool typeVariableAccessNeedsSubstitution( 3029 bool typeVariableAccessNeedsSubstitution(
3030 TypeVariableEntity element, TypeMask receiverMask) { 3030 TypeVariableEntity element, TypeMask receiverMask) {
3031 ClassEntity cls = element.typeDeclaration; 3031 ClassEntity cls = element.typeDeclaration;
3032 3032
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3116 registry.registerStaticUse(new StaticUse.staticInvoke( 3116 registry.registerStaticUse(new StaticUse.staticInvoke(
3117 helper, new CallStructure.unnamed(argumentCount))); 3117 helper, new CallStructure.unnamed(argumentCount)));
3118 return backend.emitter.staticFunctionAccess(helper); 3118 return backend.emitter.staticFunctionAccess(helper);
3119 } 3119 }
3120 3120
3121 @override 3121 @override
3122 void visitRef(HRef node) { 3122 void visitRef(HRef node) {
3123 visit(node.value); 3123 visit(node.value);
3124 } 3124 }
3125 } 3125 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/ssa/kernel_impact.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698