20faaa5d94
Change-Id: Ib18f554c1076f27a3f7c0df5a36410da41a1f467 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148784 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
63 lines
1.9 KiB
Dart
63 lines
1.9 KiB
Dart
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.7
|
|
|
|
/// Equivalence test functions for data objects.
|
|
|
|
library dart2js.equivalence.functions;
|
|
|
|
import 'package:compiler/src/js/js_debug.dart' as js;
|
|
import 'package:js_ast/js_ast.dart' as js;
|
|
|
|
bool areJsNodesEquivalent(js.Node node1, js.Node node2) {
|
|
return new JsEquivalenceVisitor().testNodes(node1, node2);
|
|
}
|
|
|
|
class JsEquivalenceVisitor extends js.EquivalenceVisitor {
|
|
Map<String, String> labelsMap = <String, String>{};
|
|
|
|
@override
|
|
bool failAt(js.Node node1, js.Node node2) {
|
|
print('Node mismatch:');
|
|
print(' ${node1 != null ? js.nodeToString(node1) : '<null>'}');
|
|
print(' ${node2 != null ? js.nodeToString(node2) : '<null>'}');
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
bool testValues(js.Node node1, Object value1, js.Node node2, Object value2) {
|
|
if (value1 != value2) {
|
|
print('Value mismatch:');
|
|
print(' ${value1}');
|
|
print(' ${value2}');
|
|
print('at');
|
|
print(' ${node1 != null ? js.nodeToString(node1) : '<null>'}');
|
|
print(' ${node2 != null ? js.nodeToString(node2) : '<null>'}');
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@override
|
|
bool testLabels(js.Node node1, String label1, js.Node node2, String label2) {
|
|
if (label1 == null && label2 == null) return true;
|
|
if (labelsMap.containsKey(label1)) {
|
|
String expectedValue = labelsMap[label1];
|
|
if (expectedValue != label2) {
|
|
print('Value mismatch:');
|
|
print(' ${label1}');
|
|
print(' found ${label2}, expected ${expectedValue}');
|
|
print('at');
|
|
print(' ${js.nodeToString(node1)}');
|
|
print(' ${js.nodeToString(node2)}');
|
|
}
|
|
return expectedValue == label2;
|
|
} else {
|
|
labelsMap[label1] = label2;
|
|
return true;
|
|
}
|
|
}
|
|
}
|