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

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

Issue 1004683002: Refactor IrBuilder to use SemanticVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 '../constants/expressions.dart'; 7 import '../constants/expressions.dart';
8 import '../constants/values.dart' show PrimitiveConstantValue; 8 import '../constants/values.dart' show PrimitiveConstantValue;
9 import '../dart_types.dart'; 9 import '../dart_types.dart';
10 import '../dart2jslib.dart'; 10 import '../dart2jslib.dart';
11 import '../elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../io/source_information.dart'; 12 import '../io/source_information.dart';
13 import '../tree/tree.dart' as ast; 13 import '../tree/tree.dart' as ast;
14 import 'cps_ir_nodes.dart' as ir;
floitsch 2015/03/12 18:04:02 why this change?
Johnni Winther 2015/03/16 13:28:13 Rebasing did it. Reverted.
14 import '../closure.dart' hide ClosureScope; 15 import '../closure.dart' hide ClosureScope;
15 import 'cps_ir_nodes.dart' as ir;
16 import 'cps_ir_builder_task.dart' show DartCapturedVariables; 16 import 'cps_ir_builder_task.dart' show DartCapturedVariables;
17 17
18 /// A mapping from variable elements to their compile-time values. 18 /// A mapping from variable elements to their compile-time values.
19 /// 19 ///
20 /// Map elements denoted by parameters and local variables to the 20 /// Map elements denoted by parameters and local variables to the
21 /// [ir.Primitive] that is their value. Parameters and locals are 21 /// [ir.Primitive] that is their value. Parameters and locals are
22 /// assigned indexes which can be used to refer to them. 22 /// assigned indexes which can be used to refer to them.
23 class Environment { 23 class Environment {
24 /// A map from locals to their environment index. 24 /// A map from locals to their environment index.
25 final Map<Local, int> variable2index; 25 final Map<Local, int> variable2index;
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 /// Remove an [ir.MutableVariable] for a local. 252 /// Remove an [ir.MutableVariable] for a local.
253 /// 253 ///
254 /// Subsequent access to the local will be direct rather than through the 254 /// Subsequent access to the local will be direct rather than through the
255 /// mutable variable. This is used for variables that do not spend their 255 /// mutable variable. This is used for variables that do not spend their
256 /// entire lifetime as mutable variables (e.g., variables that are boxed 256 /// entire lifetime as mutable variables (e.g., variables that are boxed
257 /// in mutable variables for a try block). 257 /// in mutable variables for a try block).
258 void removeMutableVariable(Local local); 258 void removeMutableVariable(Local local);
259 259
260 void declareLocalVariable(LocalVariableElement element, 260 void declareLocalVariable(LocalVariableElement element,
261 {ir.Primitive initialValue}); 261 {ir.Primitive initialValue});
262 ir.Primitive buildLocalGet(LocalElement element);
263 ir.Primitive buildLocalSet(LocalElement element, ir.Primitive value);
264 262
265 /// Called when entering a nested function with free variables. 263 /// Called when entering a nested function with free variables.
266 /// 264 ///
267 /// The free variables must subsequently be accessible using [buildLocalGet] 265 /// The free variables must subsequently be accessible using [buildLocalGet]
268 /// and [buildLocalSet]. 266 /// and [buildLocalSet].
269 void _enterClosureEnvironment(ClosureEnvironment env); 267 void _enterClosureEnvironment(ClosureEnvironment env);
270 268
271 /// Called when entering a function body or loop body. 269 /// Called when entering a function body or loop body.
272 /// 270 ///
273 /// This is not called for for-loops, which instead use the methods 271 /// This is not called for for-loops, which instead use the methods
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 state.localConstants, defaults); 688 state.localConstants, defaults);
691 } 689 }
692 690
693 /// Create a super invocation where the method name and the argument structure 691 /// Create a super invocation where the method name and the argument structure
694 /// are defined by [selector] and the argument values are defined by 692 /// are defined by [selector] and the argument values are defined by
695 /// [arguments]. 693 /// [arguments].
696 ir.Primitive buildSuperInvocation(Element target, 694 ir.Primitive buildSuperInvocation(Element target,
697 Selector selector, 695 Selector selector,
698 List<ir.Primitive> arguments); 696 List<ir.Primitive> arguments);
699 697
700 /// Create a setter invocation on the super class where the setter name and 698 /// Create a getter invocation of the [target] on the super class.
701 /// argument are defined by [selector] and [value], respectively. 699 ir.Primitive buildSuperGet(Element target) {
702 void buildSuperSet(Element target, Selector selector, ir.Primitive value) { 700 Selector selector = new Selector.getter(target.name, target.library);
701 return buildSuperInvocation(target, selector, const <ir.Primitive>[]);
702 }
703
704 /// Create a setter invocation of the [target] on the super class of with
705 /// [value].
706 ir.Primitive buildSuperSet(Element target, ir.Primitive value) {
707 Selector selector = new Selector.setter(target.name, target.library);
703 buildSuperInvocation(target, selector, [value]); 708 buildSuperInvocation(target, selector, [value]);
709 return value;
704 } 710 }
705 711
706 /// Create an index set invocation on the super class with the provided 712 /// Create an index set invocation on the super class with the provided
707 /// [index] and [value]. 713 /// [index] and [value].
708 ir.Primitive buildSuperIndexSet(Element target, 714 ir.Primitive buildSuperIndexSet(Element target,
709 ir.Primitive index, 715 ir.Primitive index,
710 ir.Primitive value) { 716 ir.Primitive value) {
711 _buildInvokeSuper(target, new Selector.indexSet(), 717 _buildInvokeSuper(target, new Selector.indexSet(),
712 <ir.Primitive>[index, value]); 718 <ir.Primitive>[index, value]);
713 return value; 719 return value;
(...skipping 28 matching lines...) Expand all
742 /// Create a dynamic index set invocation on [receiver] with the provided 748 /// Create a dynamic index set invocation on [receiver] with the provided
743 /// [index] and [value]. 749 /// [index] and [value].
744 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver, 750 ir.Primitive buildDynamicIndexSet(ir.Primitive receiver,
745 ir.Primitive index, 751 ir.Primitive index,
746 ir.Primitive value) { 752 ir.Primitive value) {
747 _buildInvokeDynamic( 753 _buildInvokeDynamic(
748 receiver, new Selector.indexSet(), <ir.Primitive>[index, value]); 754 receiver, new Selector.indexSet(), <ir.Primitive>[index, value]);
749 return value; 755 return value;
750 } 756 }
751 757
758 /// Create a read access of [local].
759 ir.Primitive buildLocalGet(LocalElement element);
760
761 /// Create a write access to [local] with the provided [value].
762 ir.Primitive buildLocalSet(LocalElement element, ir.Primitive value);
763
764 /// Create an invocation of the local [element] where argument structure is
765 /// defined by [selector] and the argument values are defined by [arguments].
766 ir.Primitive buildLocalInvocation(LocalElement element,
767 Selector selector,
768 List<ir.Primitive> arguments) {
769 return buildCallInvocation(buildLocalGet(element), selector, arguments);
770 }
771
752 /// Create a static invocation of [element] where argument structure is 772 /// Create a static invocation of [element] where argument structure is
753 /// defined by [selector] and the argument values are defined by [arguments]. 773 /// defined by [selector] and the argument values are defined by [arguments].
754 ir.Primitive buildStaticInvocation(Element element, 774 ir.Primitive buildStaticInvocation(Element element,
755 Selector selector, 775 Selector selector,
756 List<ir.Primitive> arguments, 776 List<ir.Primitive> arguments,
757 {SourceInformation sourceInformation}) { 777 {SourceInformation sourceInformation}) {
758 return _buildInvokeStatic(element, selector, arguments, sourceInformation); 778 return _buildInvokeStatic(element, selector, arguments, sourceInformation);
759 } 779 }
760 780
761 /// Create a static getter invocation of [element] where the getter name is 781 /// Create a static getter invocation of [element] where the getter name is
762 /// defined by [selector]. 782 /// defined by [selector].
763 ir.Primitive buildStaticGet(Element element, 783 ir.Primitive buildStaticGet(Element element,
764 Selector selector,
765 {SourceInformation sourceInformation}) { 784 {SourceInformation sourceInformation}) {
766 assert(selector.isGetter);
767 // TODO(karlklose,sigurdm): build different nodes for getters. 785 // TODO(karlklose,sigurdm): build different nodes for getters.
floitsch 2015/03/12 18:04:02 I guess this comment should be one down.
Johnni Winther 2015/03/16 13:28:13 Done.
786 Selector selector = new Selector.getter(element.name, element.library);
768 return _buildInvokeStatic( 787 return _buildInvokeStatic(
769 element, selector, const <ir.Primitive>[], sourceInformation); 788 element, selector, const <ir.Primitive>[], sourceInformation);
770 } 789 }
771 790
772 /// Create a static setter invocation of [element] where the setter name and 791 /// Create a static setter invocation of [element] where the setter name and
773 /// argument are defined by [selector] and [value], respectively. 792 /// argument are defined by [selector] and [value], respectively.
774 ir.Primitive buildStaticSet(Element element, 793 ir.Primitive buildStaticSet(Element element,
775 Selector selector,
776 ir.Primitive value, 794 ir.Primitive value,
777 {SourceInformation sourceInformation}) { 795 {SourceInformation sourceInformation}) {
778 assert(selector.isSetter);
779 // TODO(karlklose,sigurdm): build different nodes for setters. 796 // TODO(karlklose,sigurdm): build different nodes for setters.
floitsch 2015/03/12 18:04:02 ditto.
Johnni Winther 2015/03/16 13:28:13 Done.
797 Selector selector = new Selector.setter(element.name, element.library);
780 _buildInvokeStatic( 798 _buildInvokeStatic(
781 element, selector, <ir.Primitive>[value], sourceInformation); 799 element, selector, <ir.Primitive>[value], sourceInformation);
782 return value; 800 return value;
783 } 801 }
784 802
785 /// Create a constructor invocation of [element] on [type] where the 803 /// Create a constructor invocation of [element] on [type] where the
786 /// constructor name and argument structure are defined by [selector] and the 804 /// constructor name and argument structure are defined by [selector] and the
787 /// argument values are defined by [arguments]. 805 /// argument values are defined by [arguments].
788 ir.Primitive buildConstructorInvocation(FunctionElement element, 806 ir.Primitive buildConstructorInvocation(FunctionElement element,
789 Selector selector, 807 Selector selector,
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 } 1161 }
1144 1162
1145 ir.Parameter currentValue = new ir.Parameter(null); 1163 ir.Parameter currentValue = new ir.Parameter(null);
1146 ir.Continuation currentInvoked = new ir.Continuation([currentValue]); 1164 ir.Continuation currentInvoked = new ir.Continuation([currentValue]);
1147 bodyBuilder.add(new ir.LetCont(currentInvoked, 1165 bodyBuilder.add(new ir.LetCont(currentInvoked,
1148 new ir.InvokeMethod(iterator, new Selector.getter("current", null), 1166 new ir.InvokeMethod(iterator, new Selector.getter("current", null),
1149 currentInvoked, emptyArguments))); 1167 currentInvoked, emptyArguments)));
1150 if (Elements.isLocal(variableElement)) { 1168 if (Elements.isLocal(variableElement)) {
1151 bodyBuilder.buildLocalSet(variableElement, currentValue); 1169 bodyBuilder.buildLocalSet(variableElement, currentValue);
1152 } else if (Elements.isStaticOrTopLevel(variableElement)) { 1170 } else if (Elements.isStaticOrTopLevel(variableElement)) {
1153 bodyBuilder.buildStaticSet( 1171 bodyBuilder.buildStaticSet(variableElement, currentValue);
1154 variableElement, variableSelector, currentValue);
1155 } else { 1172 } else {
1156 ir.Primitive receiver = bodyBuilder.buildThis(); 1173 ir.Primitive receiver = bodyBuilder.buildThis();
1157 bodyBuilder.buildDynamicSet(receiver, variableSelector, currentValue); 1174 bodyBuilder.buildDynamicSet(receiver, variableSelector, currentValue);
1158 } 1175 }
1159 1176
1160 buildBody(bodyBuilder); 1177 buildBody(bodyBuilder);
1161 assert(state.breakCollectors.last == breakCollector); 1178 assert(state.breakCollectors.last == breakCollector);
1162 assert(state.continueCollectors.last == continueCollector); 1179 assert(state.continueCollectors.last == continueCollector);
1163 state.breakCollectors.removeLast(); 1180 state.breakCollectors.removeLast();
1164 state.continueCollectors.removeLast(); 1181 state.continueCollectors.removeLast();
(...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 // TODO(johnniwinther): Support passing of [DartType] for the exception. 2340 // TODO(johnniwinther): Support passing of [DartType] for the exception.
2324 class CatchClauseInfo { 2341 class CatchClauseInfo {
2325 final LocalVariableElement exceptionVariable; 2342 final LocalVariableElement exceptionVariable;
2326 final LocalVariableElement stackTraceVariable; 2343 final LocalVariableElement stackTraceVariable;
2327 final SubbuildFunction buildCatchBlock; 2344 final SubbuildFunction buildCatchBlock;
2328 2345
2329 CatchClauseInfo({this.exceptionVariable, 2346 CatchClauseInfo({this.exceptionVariable,
2330 this.stackTraceVariable, 2347 this.stackTraceVariable,
2331 this.buildCatchBlock}); 2348 this.buildCatchBlock});
2332 } 2349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698