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

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

Issue 1227543008: dart2js cps: Generate direct field accesses a build-time. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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/values.dart' show ConstantValue, PrimitiveConstantValue; 9 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 List<ir.Primitive> arguments) { 862 List<ir.Primitive> arguments) {
863 return _buildInvokeDynamic(receiver, selector, mask, arguments); 863 return _buildInvokeDynamic(receiver, selector, mask, arguments);
864 } 864 }
865 865
866 /// Create a dynamic getter invocation on [receiver] where the getter name is 866 /// Create a dynamic getter invocation on [receiver] where the getter name is
867 /// defined by [selector]. 867 /// defined by [selector].
868 ir.Primitive buildDynamicGet(ir.Primitive receiver, 868 ir.Primitive buildDynamicGet(ir.Primitive receiver,
869 Selector selector, 869 Selector selector,
870 TypeMask mask) { 870 TypeMask mask) {
871 assert(selector.isGetter); 871 assert(selector.isGetter);
872 return _buildInvokeDynamic( 872 FieldElement field = program.locateSingleField(selector, mask);
873 receiver, selector, mask, const <ir.Primitive>[]); 873 if (field != null) {
874 // If the world says this resolves to a unique field, then it MUST be
875 // treated as a field access, since the getter might not be emitted.
876 return buildFieldGet(receiver, field);
877 } else {
878 return _buildInvokeDynamic(
879 receiver, selector, mask, const <ir.Primitive>[]);
880 }
874 } 881 }
875 882
876 /// Create a dynamic setter invocation on [receiver] where the setter name and 883 /// Create a dynamic setter invocation on [receiver] where the setter name and
877 /// argument are defined by [selector] and [value], respectively. 884 /// argument are defined by [selector] and [value], respectively.
878 ir.Primitive buildDynamicSet(ir.Primitive receiver, 885 ir.Primitive buildDynamicSet(ir.Primitive receiver,
879 Selector selector, 886 Selector selector,
880 TypeMask mask, 887 TypeMask mask,
881 ir.Primitive value) { 888 ir.Primitive value) {
882 assert(selector.isSetter); 889 assert(selector.isSetter);
883 _buildInvokeDynamic(receiver, selector, mask, <ir.Primitive>[value]); 890 FieldElement field = program.locateSingleField(selector, mask);
891 if (field != null) {
892 // If the world says this resolves to a unique field, then it MUST be
893 // treated as a field access, since the setter might not be emitted.
894 buildFieldSet(receiver, field, value);
895 } else {
896 _buildInvokeDynamic(receiver, selector, mask, <ir.Primitive>[value]);
897 }
884 return value; 898 return value;
885 } 899 }
886 900
887 /// Create a dynamic index set invocation on [receiver] with the provided 901 /// Create a dynamic index set invocation on [receiver] with the provided
888 /// [index] and [value]. 902 /// [index] and [value].
889 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver, 903 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver,
890 TypeMask mask, 904 TypeMask mask,
891 ir.Primitive index, 905 ir.Primitive index,
892 ir.Primitive value) { 906 ir.Primitive value) {
893 _buildInvokeDynamic( 907 _buildInvokeDynamic(
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 /// Creates an access to the receiver from the current (or enclosing) method. 2402 /// Creates an access to the receiver from the current (or enclosing) method.
2389 /// 2403 ///
2390 /// If inside a closure class, [buildThis] will redirect access through 2404 /// If inside a closure class, [buildThis] will redirect access through
2391 /// closure fields in order to access the receiver from the enclosing method. 2405 /// closure fields in order to access the receiver from the enclosing method.
2392 ir.Primitive buildThis() { 2406 ir.Primitive buildThis() {
2393 if (state.enclosingThis != null) return state.enclosingThis; 2407 if (state.enclosingThis != null) return state.enclosingThis;
2394 assert(state.thisParameter != null); 2408 assert(state.thisParameter != null);
2395 return state.thisParameter; 2409 return state.thisParameter;
2396 } 2410 }
2397 2411
2412 ir.Primitive buildFieldGet(ir.Primitive receiver, FieldElement target) {
2413 return addPrimitive(new ir.GetField(receiver, target));
2414 }
2415
2416 void buildFieldSet(ir.Primitive receiver,
2417 FieldElement target,
2418 ir.Primitive value) {
2419 add(new ir.SetField(receiver, target, value));
2420 }
2421
2398 ir.Primitive buildSuperFieldGet(FieldElement target) { 2422 ir.Primitive buildSuperFieldGet(FieldElement target) {
2399 return addPrimitive(new ir.GetField(buildThis(), target)); 2423 return addPrimitive(new ir.GetField(buildThis(), target));
2400 } 2424 }
2401 2425
2402 ir.Primitive buildSuperFieldSet(FieldElement target, ir.Primitive value) { 2426 ir.Primitive buildSuperFieldSet(FieldElement target, ir.Primitive value) {
2403 add(new ir.SetField(buildThis(), target, value)); 2427 add(new ir.SetField(buildThis(), target, value));
2404 return value; 2428 return value;
2405 } 2429 }
2406 2430
2407 ir.Primitive buildInvokeDirectly(FunctionElement target, 2431 ir.Primitive buildInvokeDirectly(FunctionElement target,
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 } 2722 }
2699 2723
2700 class SwitchCaseInfo { 2724 class SwitchCaseInfo {
2701 final List<ir.Primitive> constants = <ir.Primitive>[]; 2725 final List<ir.Primitive> constants = <ir.Primitive>[];
2702 final SubbuildFunction buildBody; 2726 final SubbuildFunction buildBody;
2703 2727
2704 SwitchCaseInfo(this.buildBody); 2728 SwitchCaseInfo(this.buildBody);
2705 2729
2706 void addConstant(ir.Primitive constant) => constants.add(constant); 2730 void addConstant(ir.Primitive constant) => constants.add(constant);
2707 } 2731 }
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