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

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

Issue 968843003: Implement type argument access and reification of runtime types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Unbreak long line. 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 // IrNodes are kept in a separate library to have precise control over their 5 // IrNodes are kept in a separate library to have precise control over their
6 // dependencies on other parts of the system. 6 // dependencies on other parts of the system.
7 library dart2js.ir_nodes; 7 library dart2js.ir_nodes;
8 8
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../constants/values.dart' as values show ConstantValue; 10 import '../constants/values.dart' as values show ConstantValue;
11 import '../cps_ir/optimizers.dart'; 11 import '../cps_ir/optimizers.dart';
12 import '../dart_types.dart' show DartType, GenericType; 12 import '../dart_types.dart' show DartType, GenericType, TypeVariableType;
13 import '../dart2jslib.dart' as dart2js show 13 import '../dart2jslib.dart' as dart2js show
14 CURRENT_ELEMENT_SPANNABLE, 14 CURRENT_ELEMENT_SPANNABLE,
15 InternalErrorFunction, 15 InternalErrorFunction,
16 invariant; 16 invariant;
17 import '../elements/elements.dart'; 17 import '../elements/elements.dart';
18 import '../io/source_information.dart' show SourceInformation; 18 import '../io/source_information.dart' show SourceInformation;
19 import '../universe/universe.dart' show Selector, SelectorKind; 19 import '../universe/universe.dart' show Selector, SelectorKind;
20 20
21 abstract class Node { 21 abstract class Node {
22 /// A pointer to the parent node. Is null until set by optimization passes. 22 /// A pointer to the parent node. Is null until set by optimization passes.
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 639 }
640 640
641 class This extends Primitive { 641 class This extends Primitive {
642 This(); 642 This();
643 643
644 accept(Visitor visitor) => visitor.visitThis(this); 644 accept(Visitor visitor) => visitor.visitThis(this);
645 } 645 }
646 646
647 /// Reify the given type variable as a [Type]. 647 /// Reify the given type variable as a [Type].
648 /// This depends on the current binding of 'this'. 648 /// This depends on the current binding of 'this'.
649 class ReifyTypeVar extends Primitive { 649 class ReifyTypeVar extends Primitive implements DartSpecificNode {
650 final TypeVariableElement typeVariable; 650 final TypeVariableElement typeVariable;
651 651
652 ReifyTypeVar(this.typeVariable); 652 ReifyTypeVar(this.typeVariable);
653 653
654 values.ConstantValue get constant => null; 654 values.ConstantValue get constant => null;
655 655
656 accept(Visitor visitor) => visitor.visitReifyTypeVar(this); 656 accept(Visitor visitor) => visitor.visitReifyTypeVar(this);
657 } 657 }
658 658
659 class LiteralList extends Primitive { 659 class LiteralList extends Primitive {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 ConstructorElement element, 861 ConstructorElement element,
862 List<Definition> parameters, 862 List<Definition> parameters,
863 List<ConstantExpression> defaultParameterValues) 863 List<ConstantExpression> defaultParameterValues)
864 : initializers = null, 864 : initializers = null,
865 super.abstract(element, parameters, defaultParameterValues); 865 super.abstract(element, parameters, defaultParameterValues);
866 866
867 accept(Visitor visitor) => visitor.visitConstructorDefinition(this); 867 accept(Visitor visitor) => visitor.visitConstructorDefinition(this);
868 applyPass(Pass pass) => pass.rewriteConstructorDefinition(this); 868 applyPass(Pass pass) => pass.rewriteConstructorDefinition(this);
869 } 869 }
870 870
871 /// Converts the internal representation of a type to a Dart object of type
872 /// [Type].
873 class ReifyRuntimeType extends Primitive implements JsSpecificNode {
874 /// Reference to the internal representation of a type (as produced, for
875 /// example, by [ReadTypeVariable]).
876 final Reference<Primitive> value;
877 ReifyRuntimeType(Primitive value)
878 : this.value = new Reference<Primitive>(value);
879
880 @override
881 accept(Visitor visitor) => visitor.visitReifyRuntimeType(this);
882 }
883
884 /// Read the value the type variable [variable] from the target object.
885 ///
886 /// The resulting value is an internal representation (and not neccessarily a
887 /// Dart object), and must be reified by [ReifyRuntimeType], if it should be
888 /// used as a Dart value.
889 class ReadTypeVariable extends Primitive implements JsSpecificNode {
890 final TypeVariableType variable;
891 final Reference<Primitive> target;
892
893 ReadTypeVariable(this.variable, Primitive target)
894 : this.target = new Reference<Primitive>(target);
895
896 @override
897 accept(Visitor visitor) => visitor.visitReadTypeVariable(this);
898 }
899
871 List<Reference<Primitive>> _referenceList(Iterable<Primitive> definitions) { 900 List<Reference<Primitive>> _referenceList(Iterable<Primitive> definitions) {
872 return definitions.map((e) => new Reference<Primitive>(e)).toList(); 901 return definitions.map((e) => new Reference<Primitive>(e)).toList();
873 } 902 }
874 903
875 abstract class Visitor<T> { 904 abstract class Visitor<T> {
876 const Visitor(); 905 const Visitor();
877 906
878 T visit(Node node); 907 T visit(Node node);
879 908
880 // Concrete classes. 909 // Concrete classes.
(...skipping 27 matching lines...) Expand all
908 T visitLiteralMap(LiteralMap node); 937 T visitLiteralMap(LiteralMap node);
909 T visitConstant(Constant node); 938 T visitConstant(Constant node);
910 T visitThis(This node); 939 T visitThis(This node);
911 T visitReifyTypeVar(ReifyTypeVar node); 940 T visitReifyTypeVar(ReifyTypeVar node);
912 T visitCreateFunction(CreateFunction node); 941 T visitCreateFunction(CreateFunction node);
913 T visitGetMutableVariable(GetMutableVariable node); 942 T visitGetMutableVariable(GetMutableVariable node);
914 T visitParameter(Parameter node); 943 T visitParameter(Parameter node);
915 T visitContinuation(Continuation node); 944 T visitContinuation(Continuation node);
916 T visitMutableVariable(MutableVariable node); 945 T visitMutableVariable(MutableVariable node);
917 946
947 // JavaScript specific nodes.
948
918 // Conditions. 949 // Conditions.
919 T visitIsTrue(IsTrue node); 950 T visitIsTrue(IsTrue node);
920 951
921 // JavaScript specific nodes.
922 // Expressions. 952 // Expressions.
923 T visitSetField(SetField node); 953 T visitSetField(SetField node);
954
924 // Definitions. 955 // Definitions.
925 T visitIdentical(Identical node); 956 T visitIdentical(Identical node);
926 T visitInterceptor(Interceptor node); 957 T visitInterceptor(Interceptor node);
927 T visitCreateInstance(CreateInstance node); 958 T visitCreateInstance(CreateInstance node);
928 T visitGetField(GetField node); 959 T visitGetField(GetField node);
929 T visitCreateBox(CreateBox node); 960 T visitCreateBox(CreateBox node);
961 T visitReifyRuntimeType(ReifyRuntimeType node);
962 T visitReadTypeVariable(ReadTypeVariable node);
930 } 963 }
931 964
932 /// Recursively visits the entire CPS term, and calls abstract `process*` 965 /// Recursively visits the entire CPS term, and calls abstract `process*`
933 /// (i.e. `processLetPrim`) functions in pre-order. 966 /// (i.e. `processLetPrim`) functions in pre-order.
934 class RecursiveVisitor implements Visitor { 967 class RecursiveVisitor implements Visitor {
935 const RecursiveVisitor(); 968 const RecursiveVisitor();
936 969
937 visit(Node node) => node.accept(this); 970 visit(Node node) => node.accept(this);
938 971
939 processReference(Reference ref) {} 972 processReference(Reference ref) {}
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 processGetField(GetField node) {} 1213 processGetField(GetField node) {}
1181 visitGetField(GetField node) { 1214 visitGetField(GetField node) {
1182 processGetField(node); 1215 processGetField(node);
1183 processReference(node.object); 1216 processReference(node.object);
1184 } 1217 }
1185 1218
1186 processCreateBox(CreateBox node) {} 1219 processCreateBox(CreateBox node) {}
1187 visitCreateBox(CreateBox node) { 1220 visitCreateBox(CreateBox node) {
1188 processCreateBox(node); 1221 processCreateBox(node);
1189 } 1222 }
1223
1224 processReifyRuntimeType(ReifyRuntimeType node) {}
1225 visitReifyRuntimeType(ReifyRuntimeType node) {
1226 processReifyRuntimeType(node);
1227 processReference(node.value);
1228 }
1229
1230 processReadTypeVariable(ReadTypeVariable node) {}
1231 visitReadTypeVariable(ReadTypeVariable node) {
1232 processReadTypeVariable(node);
1233 processReference(node.target);
1234 }
1190 } 1235 }
1191 1236
1192 /// Keeps track of currently unused register indices. 1237 /// Keeps track of currently unused register indices.
1193 class RegisterArray { 1238 class RegisterArray {
1194 int nextIndex = 0; 1239 int nextIndex = 0;
1195 final List<int> freeStack = <int>[]; 1240 final List<int> freeStack = <int>[];
1196 1241
1197 /// Returns an index that is currently unused. 1242 /// Returns an index that is currently unused.
1198 int makeIndex() { 1243 int makeIndex() {
1199 if (freeStack.isEmpty) { 1244 if (freeStack.isEmpty) {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 } 1489 }
1445 1490
1446 void visitIdentical(Identical node) { 1491 void visitIdentical(Identical node) {
1447 visitReference(node.left); 1492 visitReference(node.left);
1448 visitReference(node.right); 1493 visitReference(node.right);
1449 } 1494 }
1450 1495
1451 void visitInterceptor(Interceptor node) { 1496 void visitInterceptor(Interceptor node) {
1452 visitReference(node.input); 1497 visitReference(node.input);
1453 } 1498 }
1499
1500 void visitReifyRuntimeType(ReifyRuntimeType node) {
1501 visitReference(node.value);
1502 }
1503
1504 void visitReadTypeVariable(ReadTypeVariable node) {
1505 visitReference(node.target);
1506 }
1454 } 1507 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_visitor.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698