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

Unified Diff: sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart

Issue 705023002: dart2js: Add a type parameter to class Reference in the CPS IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart
diff --git a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart
index 4ea9bebb5900e8c8b9236a5ab003c9ac7846253d..7b5861e4d927cb3155e667c89ea0a0840e2fd6dd 100644
--- a/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart
+++ b/sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_nodes.dart
@@ -29,9 +29,9 @@ abstract class Expression extends Node {
/// The base class of things that variables can refer to: primitives,
/// continuations, function and continuation parameters, etc.
-abstract class Definition extends Node {
+abstract class Definition<T extends Definition<T>> extends Node {
Kevin Millikin (Google) 2014/11/06 10:35:50 Is T the canonical type variable name?
karlklose 2014/11/06 11:33:51 I think it is used in most Dart code. Some tests u
// The head of a linked-list of occurrences, in no particular order.
- Reference firstRef = null;
+ Reference<T> firstRef;
bool get hasAtMostOneUse => firstRef == null || firstRef.next == null;
bool get hasExactlyOneUse => firstRef != null && firstRef.next == null;
@@ -40,7 +40,7 @@ abstract class Definition extends Node {
void substituteFor(Definition other) {
if (other.firstRef == null) return;
- Reference previous, current = other.firstRef;
+ Reference<T> previous, current = other.firstRef;
do {
current.definition = this;
previous = current;
@@ -58,7 +58,7 @@ abstract class Definition extends Node {
/// Primitives may allocate objects, this is not considered side-effect here.
///
/// Although primitives may not mutate state, they may depend on state.
-abstract class Primitive extends Definition {
+abstract class Primitive extends Definition<Primitive> {
/// The [VariableElement] or [ParameterElement] from which the primitive
/// binding originated.
Element hint;
@@ -80,10 +80,10 @@ abstract class Primitive extends Definition {
/// Operands to invocations and primitives are always variables. They point to
/// their definition and are doubly-linked into a list of occurrences.
-class Reference {
- Definition definition;
- Reference previous = null;
- Reference next = null;
+class Reference<T extends Definition<T>> {
+ T definition;
+ Reference<T> previous;
+ Reference<T> next;
/// A pointer to the parent node. Is null until set by optimization passes.
Node parent;
@@ -146,7 +146,7 @@ class LetCont extends Expression implements InteriorNode {
abstract class Invoke {
Selector get selector;
- List<Reference> get arguments;
+ List<Reference<Primitive>> get arguments;
}
/// Represents a node with a child node, which can be accessed through the
@@ -173,12 +173,12 @@ class InvokeStatic extends Expression implements Invoke {
*/
final Selector selector;
- final Reference continuation;
- final List<Reference> arguments;
+ final Reference<Continuation> continuation;
+ final List<Reference<Primitive>> arguments;
InvokeStatic(this.target, this.selector, Continuation cont,
- List<Definition> args)
- : continuation = new Reference(cont),
+ List<Primitive> args)
+ : continuation = new Reference<Continuation>(cont),
arguments = _referenceList(args) {
assert(target is ErroneousElement || selector.name == target.name);
}
@@ -189,17 +189,17 @@ class InvokeStatic extends Expression implements Invoke {
/// Invoke a method, operator, getter, setter, or index getter/setter.
/// Converting a method to a function object is treated as a getter invocation.
class InvokeMethod extends Expression implements Invoke {
- final Reference receiver;
+ final Reference<Primitive> receiver;
final Selector selector;
- final Reference continuation;
- final List<Reference> arguments;
+ final Reference<Continuation> continuation;
+ final List<Reference<Primitive>> arguments;
- InvokeMethod(Definition receiver,
+ InvokeMethod(Primitive receiver,
this.selector,
Continuation cont,
- List<Definition> args)
- : receiver = new Reference(receiver),
- continuation = new Reference(cont),
+ List<Primitive> args)
+ : receiver = new Reference<Primitive>(receiver),
+ continuation = new Reference<Continuation>(cont),
arguments = _referenceList(args) {
assert(selector != null);
assert(selector.kind == SelectorKind.CALL ||
@@ -217,13 +217,13 @@ class InvokeMethod extends Expression implements Invoke {
/// super class in tail position.
class InvokeSuperMethod extends Expression implements Invoke {
final Selector selector;
- final Reference continuation;
- final List<Reference> arguments;
+ final Reference<Continuation> continuation;
+ final List<Reference<Primitive>> arguments;
InvokeSuperMethod(this.selector,
Continuation cont,
- List<Definition> args)
- : continuation = new Reference(cont),
+ List<Primitive> args)
+ : continuation = new Reference<Continuation>(cont),
arguments = _referenceList(args) {
assert(selector != null);
assert(selector.kind == SelectorKind.CALL ||
@@ -242,8 +242,8 @@ class InvokeSuperMethod extends Expression implements Invoke {
class InvokeConstructor extends Expression implements Invoke {
final DartType type;
final FunctionElement target;
- final Reference continuation;
- final List<Reference> arguments;
+ final Reference<Continuation> continuation;
+ final List<Reference<Primitive>> arguments;
final Selector selector;
/// The class being instantiated. This is the same as `target.enclosingClass`
@@ -257,8 +257,8 @@ class InvokeConstructor extends Expression implements Invoke {
this.target,
this.selector,
Continuation cont,
- List<Definition> args)
- : continuation = new Reference(cont),
+ List<Primitive> args)
+ : continuation = new Reference<Continuation>(cont),
arguments = _referenceList(args) {
assert(dart2js.invariant(target,
target.isErroneous || target.isConstructor,
@@ -302,11 +302,11 @@ class TypeOperator extends Expression {
/// Invoke [toString] on each argument and concatenate the results.
class ConcatenateStrings extends Expression {
- final Reference continuation;
- final List<Reference> arguments;
+ final Reference<Continuation> continuation;
+ final List<Reference<Definition>> arguments;
- ConcatenateStrings(Continuation cont, List<Definition> args)
- : continuation = new Reference(cont),
+ ConcatenateStrings(Continuation cont, List<Primitive> args)
+ : continuation = new Reference<Continuation>(cont),
arguments = _referenceList(args);
accept(Visitor visitor) => visitor.visitConcatenateStrings(this);
@@ -528,7 +528,7 @@ class Parameter extends Primitive {
/// Continuations are normally bound by 'let cont'. A continuation with one
/// parameter and no body is used to represent a function's return continuation.
/// The return continuation is bound by the Function, not by 'let cont'.
-class Continuation extends Definition implements InteriorNode {
+class Continuation extends Definition<Continuation> implements InteriorNode {
final List<Parameter> parameters;
Expression body = null;
@@ -575,8 +575,8 @@ class FunctionDefinition extends Node implements InteriorNode {
bool get isAbstract => body == null;
}
-List<Reference> _referenceList(Iterable<Definition> definitions) {
- return definitions.map((e) => new Reference(e)).toList();
+List<Reference<Primitive>> _referenceList(Iterable<Primitive> definitions) {
+ return definitions.map((e) => new Reference<Primitive>(e)).toList();
}
abstract class Visitor<T> {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698