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

Unified Diff: tests/compiler/dart2js/closure/closure_test.dart

Issue 2951723002: Add closure_test for kernel based members (Closed)
Patch Set: Cleanup 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/closure/closure_test.dart
diff --git a/tests/compiler/dart2js/closure/closure_test.dart b/tests/compiler/dart2js/closure/closure_test.dart
index 1b69d6d370852d20a31dbd2c98a8f246bb52366b..8db19bd1915d59c5dc17b814634bc902a93667df 100644
--- a/tests/compiler/dart2js/closure/closure_test.dart
+++ b/tests/compiler/dart2js/closure/closure_test.dart
@@ -5,13 +5,17 @@
import 'dart:io';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/closure.dart';
+import 'package:compiler/src/common.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/elements/entities.dart';
-import 'package:compiler/src/tree/nodes.dart';
+import 'package:compiler/src/kernel/element_map.dart';
+import 'package:compiler/src/kernel/kernel_backend_strategy.dart';
+import 'package:compiler/src/tree/nodes.dart' as ast;
import '../equivalence/id_equivalence.dart';
import '../equivalence/id_equivalence_helper.dart';
+import 'package:kernel/ast.dart' as ir;
main() {
asyncTest(() async {
@@ -19,44 +23,114 @@ main() {
await for (FileSystemEntity entity in dataDir.list()) {
print('Checking ${entity.uri}');
String annotatedCode = await new File.fromUri(entity.uri).readAsString();
- await checkCode(annotatedCode, checkClosureData);
+ await checkCode(annotatedCode, computeClosureData, compileFromSource);
+ await checkCode(annotatedCode, computeKernelClosureData, compileFromDill);
}
});
}
-void checkClosureData(
- Compiler compiler, Map<Id, String> expectedMap, MemberEntity _member) {
+/// Compute closure data mapping for [_member] as a [MemberElement].
+///
+/// Fills [actualMap] with the data and [sourceSpanMap] with the source spans
+/// for the data origin.
+void computeClosureData(Compiler compiler, MemberEntity _member,
+ Map<Id, String> actualMap, Map<Id, SourceSpan> sourceSpanMap) {
MemberElement member = _member;
- new ClosureChecker(compiler.reporter, expectedMap, member.resolvedAst,
- compiler.backendStrategy.closureDataLookup as ClosureDataLookup<Node>)
- .check();
+ ClosureDataLookup<ast.Node> closureDataLookup =
+ compiler.backendStrategy.closureDataLookup as ClosureDataLookup<ast.Node>;
+ new ClosureAstComputer(compiler.reporter, actualMap, sourceSpanMap,
+ member.resolvedAst, closureDataLookup)
+ .run();
}
-class ClosureChecker extends AbstractResolvedAstChecker {
- final ClosureDataLookup<Node> closureDataLookup;
+/// Compute closure data mapping for [member] as a kernel based element.
+///
+/// Fills [actualMap] with the data and [sourceSpanMap] with the source spans
+/// for the data origin.
+void computeKernelClosureData(Compiler compiler, MemberEntity member,
+ Map<Id, String> actualMap, Map<Id, SourceSpan> sourceSpanMap) {
+ KernelBackendStrategy backendStrategy = compiler.backendStrategy;
+ KernelToElementMap elementMap = backendStrategy.elementMap;
+ GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting;
+ ClosureDataLookup closureDataLookup = backendStrategy.closureDataLookup;
+ new ClosureIrChecker(actualMap, sourceSpanMap, elementMap, member,
+ localsMap.getLocalsMap(member), closureDataLookup)
+ .run(elementMap.getMemberNode(member));
+}
+
+/// Ast visitor for computing closure data.
+class ClosureAstComputer extends AbstractResolvedAstComputer {
+ final ClosureDataLookup<ast.Node> closureDataLookup;
final ClosureRepresentationInfo info;
- ClosureChecker(DiagnosticReporter reporter, Map<Id, String> expectedMap,
- ResolvedAst resolvedAst, this.closureDataLookup)
+ ClosureAstComputer(
+ DiagnosticReporter reporter,
+ Map<Id, String> actualMap,
+ Map<Id, Spannable> spannableMap,
+ ResolvedAst resolvedAst,
+ this.closureDataLookup)
: this.info =
closureDataLookup.getClosureRepresentationInfo(resolvedAst.element),
- super(reporter, expectedMap, resolvedAst);
+ super(reporter, actualMap, spannableMap, resolvedAst);
@override
- String computeNodeValue(Node node, [AstElement element]) {
+ String computeNodeValue(ast.Node node, [AstElement element]) {
if (element != null && element.isLocal) {
LocalElement local = element;
- StringBuffer sb = new StringBuffer();
- if (info.variableIsUsedInTryOrSync(local)) {
- sb.write('inTry');
- }
- return sb.toString();
+ return computeLocalValue(info, local);
}
+ // TODO(johnniwinther,efortuna): Collect data for other nodes?
return null;
}
@override
String computeElementValue(AstElement element) {
+ // TODO(johnniwinther,efortuna): Collect data for the member
+ // (has thisLocal, has box, etc.).
+ return null;
+ }
+}
+
+/// Kernel IR visitor for computing closure data.
+class ClosureIrChecker extends AbstractIrComputer {
+ final ClosureDataLookup<ir.Node> closureDataLookup;
+ final ClosureRepresentationInfo info;
+ final KernelToLocalsMap _localsMap;
+
+ ClosureIrChecker(
+ Map<Id, String> actualMap,
+ Map<Id, SourceSpan> sourceSpanMap,
+ KernelToElementMap elementMap,
+ MemberEntity member,
+ this._localsMap,
+ this.closureDataLookup)
+ : this.info = closureDataLookup.getClosureRepresentationInfo(member),
+ super(actualMap, sourceSpanMap);
+
+ @override
+ String computeNodeValue(ir.Node node) {
+ if (node is ir.VariableDeclaration) {
+ Local local = _localsMap.getLocal(node);
+ return computeLocalValue(info, local);
+ }
+ // TODO(johnniwinther,efortuna): Collect data for other nodes?
return null;
}
+
+ @override
+ String computeMemberValue(ir.Member member) {
+ // TODO(johnniwinther,efortuna): Collect data for the member
+ // (has thisLocal, has box, etc.).
+ return null;
+ }
+}
+
+/// Compute a string representation of the data stored for [local] in [info].
+String computeLocalValue(ClosureRepresentationInfo info, Local local) {
+ StringBuffer sb = new StringBuffer();
+ if (info.variableIsUsedInTryOrSync(local)) {
+ sb.write('inTry');
+ }
+ // TODO(johnniwinther,efortuna): Add more info (captured, boxed etc.).
+ return sb.toString();
}
« no previous file with comments | « tests/compiler/dart2js/bad_output_io_test.dart ('k') | tests/compiler/dart2js/equivalence/id_equivalence.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698