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

Unified Diff: tests/compiler/dart2js/equivalence/id_equivalence_helper.dart

Issue 2950493002: Add closure_test (Closed)
Patch Set: Created 3 years, 6 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
Index: tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
diff --git a/tests/compiler/dart2js/inference/inference_test_helper.dart b/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
similarity index 69%
copy from tests/compiler/dart2js/inference/inference_test_helper.dart
copy to tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
index e518df210771f951cfe217d6988a6db670456db2..ab3b9a7f2cf596432565097b70262ec4dba134ae 100644
--- a/tests/compiler/dart2js/inference/inference_test_helper.dart
+++ b/tests/compiler/dart2js/equivalence/id_equivalence_helper.dart
@@ -9,15 +9,14 @@ import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/resolution/tree_elements.dart';
import 'package:compiler/src/tree/nodes.dart';
-import 'package:compiler/src/types/types.dart';
import 'package:expect/expect.dart';
import '../annotated_code_helper.dart';
import '../memory_compiler.dart';
-import 'enumerator.dart';
+import '../equivalence/id_equivalence.dart';
typedef void CheckMemberFunction(
- Compiler compiler, Map<Id, String> expectedMap, MemberElement member);
+ Compiler compiler, Map<Id, String> expectedMap, MemberEntity member);
/// Compiles the [annotatedCode] with the provided [options] and calls
/// [checkMember] for each member in the code providing the map from [Id] to
@@ -32,39 +31,29 @@ checkCode(String annotatedCode, CheckMemberFunction checkMember,
compiler.stopAfterTypeInference = true;
Uri mainUri = Uri.parse('memory:main.dart');
await compiler.run(mainUri);
- LibraryElement mainApp =
- compiler.frontendStrategy.elementEnvironment.mainLibrary;
- mainApp.forEachLocalMember((dynamic member) {
- if (member.isClass) {
- member.forEachLocalMember((member) {
+ ElementEnvironment elementEnvironment =
+ compiler.backendClosedWorldForTesting.elementEnvironment;
+ LibraryEntity mainLibrary = elementEnvironment.mainLibrary;
+ elementEnvironment.forEachClass(mainLibrary, (ClassEntity cls) {
+ elementEnvironment.forEachClassMember(cls,
+ (ClassEntity declarer, MemberEntity member) {
+ if (cls == declarer) {
checkMember(compiler, expectedMap, member);
- });
- } else if (member.isTypedef) {
- // Skip.
- } else {
- checkMember(compiler, expectedMap, member);
- }
+ }
+ });
+ });
+ elementEnvironment.forEachLibraryMember(mainLibrary, (MemberEntity member) {
+ checkMember(compiler, expectedMap, member);
});
expectedMap.forEach((Id id, String expected) {
reportHere(
compiler.reporter,
- computeSpannable(compiler.resolution.elementEnvironment, mainUri, id),
+ computeSpannable(elementEnvironment, mainUri, id),
'expected:${expected},actual:null');
});
Expect.isTrue(expectedMap.isEmpty, "Ids not found: $expectedMap.");
}
-void checkMemberAstTypeMasks(
- Compiler compiler, Map<Id, String> expectedMap, MemberElement member) {
- ResolvedAst resolvedAst = member.resolvedAst;
- if (resolvedAst.kind != ResolvedAstKind.PARSED) return;
- compiler.reporter.withCurrentElement(member.implementation, () {
- new TypeMaskChecker(compiler.reporter, expectedMap, resolvedAst,
- compiler.globalInference.results)
- .check();
- });
-}
-
Spannable computeSpannable(
ElementEnvironment elementEnvironment, Uri mainUri, Id id) {
if (id is NodeId) {
@@ -101,16 +90,13 @@ Map<Id, String> computeExpectedMap(AnnotatedCode code) {
return map;
}
-class TypeMaskChecker extends Visitor with AstEnumeratorMixin {
+abstract class AbstractResolvedAstChecker extends Visitor
+ with AstEnumeratorMixin {
final DiagnosticReporter reporter;
final Map<Id, String> expectedMap;
final ResolvedAst resolvedAst;
- final GlobalTypeInferenceResults results;
- final GlobalTypeInferenceElementResult result;
- TypeMaskChecker(
- this.reporter, this.expectedMap, this.resolvedAst, this.results)
- : result = results.resultOfMember(resolvedAst.element as MemberElement);
+ AbstractResolvedAstChecker(this.reporter, this.expectedMap, this.resolvedAst);
TreeElements get elements => resolvedAst.elements;
@@ -124,36 +110,36 @@ class TypeMaskChecker extends Visitor with AstEnumeratorMixin {
void checkElement(AstElement element) {
ElementId id = computeElementId(element);
- GlobalTypeInferenceElementResult elementResult =
- results.resultOfElement(element);
- TypeMask value =
- element.isFunction ? elementResult.returnType : elementResult.type;
String expected = annotationForId(id);
+ String value = computeElementValue(element);
checkValue(element, expected, value);
}
+ String computeElementValue(AstElement element);
+
String annotationForId(Id id) {
if (id == null) return null;
return expectedMap.remove(id);
}
- void checkValue(Spannable spannable, String expected, TypeMask value) {
+ void checkValue(Spannable spannable, String expected, String value) {
if (value != null || expected != null) {
- String valueText = '$value';
- if (valueText != expected) {
+ if (value != expected) {
reportHere(reporter, spannable, 'expected:${expected},actual:${value}');
}
- Expect.equals(expected, valueText);
+ Expect.equals(expected, value);
}
}
- void checkSend(Send node) {
- NodeId id = computeNodeId(node);
- TypeMask value = result.typeOfSend(node);
+ void checkNode(Node node, AstElement element) {
+ NodeId id = computeNodeId(node, element);
String expected = annotationForId(id);
+ String value = computeNodeValue(node, element);
checkValue(node, expected, value);
}
+ String computeNodeValue(Node node, [AstElement element]);
+
visitVariableDefinitions(VariableDefinitions node) {
for (Node child in node.definitions) {
AstElement element = elements[child];
@@ -161,6 +147,8 @@ class TypeMaskChecker extends Visitor with AstEnumeratorMixin {
reportHere(reporter, child, 'No element for variable.');
} else if (!element.isLocal) {
checkElement(element);
+ } else {
+ checkNode(child, element);
}
}
visitNode(node);
@@ -168,17 +156,21 @@ class TypeMaskChecker extends Visitor with AstEnumeratorMixin {
visitFunctionExpression(FunctionExpression node) {
AstElement element = elements.getFunctionDefinition(node);
- checkElement(element);
+ if (!element.isLocal) {
+ checkElement(element);
+ } else {
+ checkNode(node, element);
+ }
visitNode(node);
}
visitSend(Send node) {
- checkSend(node);
+ checkNode(node, null);
visitNode(node);
}
visitSendSet(SendSet node) {
- checkSend(node);
+ checkNode(node, null);
visitNode(node);
}
}
« no previous file with comments | « tests/compiler/dart2js/equivalence/id_equivalence.dart ('k') | tests/compiler/dart2js/equivalence/id_equivalence_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698