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

Unified Diff: lib/src/ast.dart

Issue 1715553002: Define equality for boolean selectors. (Closed) Base URL: git@github.com:dart-lang/boolean_selector@master
Patch Set: Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/boolean_selector.dart ('k') | lib/src/impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/ast.dart
diff --git a/lib/src/ast.dart b/lib/src/ast.dart
index 26c09bfb79b69857e41f297337f4e735f9a549f3..13eb633135507b5d450d31311f9fa35f7740f42e 100644
--- a/lib/src/ast.dart
+++ b/lib/src/ast.dart
@@ -38,6 +38,10 @@ class VariableNode implements Node {
accept(Visitor visitor) => visitor.visitVariable(this);
String toString() => name;
+
+ bool operator==(other) => other is VariableNode && name == other.name;
+
+ int get hashCode => name.hashCode;
}
/// A negation expression.
@@ -56,6 +60,10 @@ class NotNode implements Node {
String toString() => child is VariableNode || child is NotNode
? "!$child"
: "!($child)";
+
+ bool operator==(other) => other is NotNode && child == other.child;
+
+ int get hashCode => ~child.hashCode;
}
/// An or expression.
@@ -87,6 +95,11 @@ class OrNode implements Node {
return "$string1 || $string2";
}
+
+ bool operator==(other) =>
+ other is OrNode && left == other.left && right == other.right;
+
+ int get hashCode => left.hashCode ^ right.hashCode;
}
/// An and expression.
@@ -118,6 +131,11 @@ class AndNode implements Node {
return "$string1 && $string2";
}
+
+ bool operator==(other) =>
+ other is AndNode && left == other.left && right == other.right;
+
+ int get hashCode => left.hashCode ^ right.hashCode;
}
/// A ternary conditional expression.
@@ -149,6 +167,15 @@ class ConditionalNode implements Node {
var trueString = whenTrue is ConditionalNode ? "($whenTrue)" : whenTrue;
return "$conditionString ? $trueString : $whenFalse";
}
+
+ bool operator==(other) =>
+ other is ConditionalNode &&
+ condition == other.condition &&
+ whenTrue == other.whenTrue &&
+ whenFalse == other.whenFalse;
+
+ int get hashCode =>
+ condition.hashCode ^ whenTrue.hashCode ^ whenFalse.hashCode;
}
/// Like [FileSpan.expand], except if [start] and [end] are `null` or from
« no previous file with comments | « lib/boolean_selector.dart ('k') | lib/src/impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698