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

Unified Diff: pkg/polymer_expressions/lib/expression.dart

Issue 74543003: Split out Index AST node from Invoke (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split out Getter too Created 7 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
Index: pkg/polymer_expressions/lib/expression.dart
diff --git a/pkg/polymer_expressions/lib/expression.dart b/pkg/polymer_expressions/lib/expression.dart
index 60b7548134ab640f8beff5a8910355041d1c1877..c89724fe8232828b3ff828bcdb1783ac7263fba6 100644
--- a/pkg/polymer_expressions/lib/expression.dart
+++ b/pkg/polymer_expressions/lib/expression.dart
@@ -18,7 +18,9 @@ ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e);
UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e);
BinaryOperator binary(Expression l, String op, Expression r) =>
new BinaryOperator(l, op, r);
-Invoke invoke(Expression e, String m, [List<Expression> a]) =>
+Getter getter(Expression e, String m) => new Getter(e, m);
+Index index(Expression e, Expression a) => new Index(e, a);
+Invoke invoke(Expression e, String m, List<Expression> a) =>
new Invoke(e, m, a);
InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
@@ -44,7 +46,11 @@ class AstFactory {
BinaryOperator binary(Expression l, String op, Expression r) =>
new BinaryOperator(l, op, r);
- Invoke invoke(Expression e, String m, [List<Expression> a]) =>
+ Getter getter(Expression g, String n) => new Getter(g, n);
+
+ Index index(Expression e, Expression a) => new Index(e, a);
+
+ Invoke invoke(Expression e, String m, List<Expression> a) =>
new Invoke(e, m, a);
InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
@@ -183,6 +189,44 @@ class InExpression extends Expression {
int get hashCode => _JenkinsSmiHash.hash2(left.hashCode, right.hashCode);
}
+class Index extends Expression {
+ final Expression receiver;
+ final Expression argument;
+
+ Index(this.receiver, this.argument);
+
+ accept(Visitor v) => v.visitIndex(this);
+
+ String toString() => '$receiver[$argument]';
+
+ bool operator ==(o) =>
+ o is Index
+ && o.receiver == receiver
+ && o.argument == argument;
+
+ int get hashCode =>
+ _JenkinsSmiHash.hash2(receiver.hashCode, argument.hashCode);
+}
+
+class Getter extends Expression {
+ final Expression receiver;
+ final String name;
+
+ Getter(this.receiver, this.name);
+
+ accept(Visitor v) => v.visitGetter(this);
+
+ String toString() => '$receiver.$name';
+
+ bool operator ==(o) =>
+ o is Getter
+ && o.receiver == receiver
+ && o.name == name;
+
+ int get hashCode => _JenkinsSmiHash.hash2(receiver.hashCode, name.hashCode);
+
+}
+
/**
* Represents a function or method invocation. If [method] is null, then
* [receiver] is an expression that should evaluate to a function. If [method]
@@ -194,12 +238,12 @@ class Invoke extends Expression {
final String method;
final List<Expression> arguments;
- Invoke(this.receiver, this.method, [this.arguments]);
+ Invoke(this.receiver, this.method, this.arguments) {
+ assert(arguments != null);
+ }
accept(Visitor v) => v.visitInvoke(this);
- bool get isGetter => arguments == null;
-
String toString() => '$receiver.$method($arguments)';
bool operator ==(o) =>
@@ -243,10 +287,11 @@ class _JenkinsSmiHash {
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
- static int hash2(a, b) => finish(combine(combine(0, a), b));
+ static int hash2(int a, int b) => finish(combine(combine(0, a), b));
- static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c));
+ static int hash3(int a, int b, int c) =>
+ finish(combine(combine(combine(0, a), b), c));
- static int hash4(a, b, c, d) =>
+ static int hash4(int a, int b, int c, int d) =>
finish(combine(combine(combine(combine(0, a), b), c), d));
}

Powered by Google App Engine
This is Rietveld 408576698