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

Side by Side Diff: tests/compiler/dart2js/closure/closure_test.dart

Issue 3007903002: Support annotations on assignment and postfix operations (Closed)
Patch Set: Updated cf. comments Created 3 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | tests/compiler/dart2js/closure/data/captured_variable.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:io' hide Link; 5 import 'dart:io' hide Link;
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import 'package:compiler/src/closure.dart'; 7 import 'package:compiler/src/closure.dart';
8 import 'package:compiler/src/commandline_options.dart'; 8 import 'package:compiler/src/commandline_options.dart';
9 import 'package:compiler/src/common.dart'; 9 import 'package:compiler/src/common.dart';
10 import 'package:compiler/src/compiler.dart'; 10 import 'package:compiler/src/compiler.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 void computeKernelClosureData( 52 void computeKernelClosureData(
53 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap, 53 Compiler compiler, MemberEntity member, Map<Id, ActualData> actualMap,
54 {bool verbose: false}) { 54 {bool verbose: false}) {
55 KernelBackendStrategy backendStrategy = compiler.backendStrategy; 55 KernelBackendStrategy backendStrategy = compiler.backendStrategy;
56 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap; 56 KernelToElementMapForBuilding elementMap = backendStrategy.elementMap;
57 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting; 57 GlobalLocalsMap localsMap = backendStrategy.globalLocalsMapForTesting;
58 ClosureDataLookup closureDataLookup = backendStrategy.closureDataLookup; 58 ClosureDataLookup closureDataLookup = backendStrategy.closureDataLookup;
59 MemberDefinition definition = elementMap.getMemberDefinition(member); 59 MemberDefinition definition = elementMap.getMemberDefinition(member);
60 assert(definition.kind == MemberKind.regular, 60 assert(definition.kind == MemberKind.regular,
61 failedAt(member, "Unexpected member definition $definition")); 61 failedAt(member, "Unexpected member definition $definition"));
62 new ClosureIrChecker(actualMap, elementMap, member, 62 new ClosureIrChecker(compiler.reporter, actualMap, elementMap, member,
63 localsMap.getLocalsMap(member), closureDataLookup, 63 localsMap.getLocalsMap(member), closureDataLookup,
64 verbose: verbose) 64 verbose: verbose)
65 .run(definition.node); 65 .run(definition.node);
66 } 66 }
67 67
68 /// Ast visitor for computing closure data. 68 /// Ast visitor for computing closure data.
69 class ClosureAstComputer extends AstDataExtractor with ComputeValueMixin { 69 class ClosureAstComputer extends AstDataExtractor with ComputeValueMixin {
70 final ClosureDataLookup<ast.Node> closureDataLookup; 70 final ClosureDataLookup<ast.Node> closureDataLookup;
71 final bool verbose; 71 final bool verbose;
72 72
(...skipping 11 matching lines...) Expand all
84 pushLocalFunction(node); 84 pushLocalFunction(node);
85 super.visitFunctionExpression(node); 85 super.visitFunctionExpression(node);
86 popLocalFunction(); 86 popLocalFunction();
87 popMember(); 87 popMember();
88 } else { 88 } else {
89 super.visitFunctionExpression(node); 89 super.visitFunctionExpression(node);
90 } 90 }
91 } 91 }
92 92
93 @override 93 @override
94 String computeNodeValue(ast.Node node, [AstElement element]) { 94 String computeNodeValue(Id id, ast.Node node, [AstElement element]) {
95 if (element != null && element.isLocal) { 95 if (element != null && element.isLocal) {
96 if (element.isFunction) { 96 if (element.isFunction) {
97 LocalFunctionElement localFunction = element; 97 LocalFunctionElement localFunction = element;
98 return computeObjectValue(localFunction.callMethod); 98 return computeObjectValue(localFunction.callMethod);
99 } else { 99 } else {
100 LocalElement local = element; 100 LocalElement local = element;
101 return computeLocalValue(local); 101 return computeLocalValue(local);
102 } 102 }
103 } 103 }
104 // TODO(johnniwinther,efortuna): Collect data for other nodes? 104 // TODO(johnniwinther,efortuna): Collect data for other nodes?
105 return null; 105 return null;
106 } 106 }
107 107
108 @override 108 @override
109 String computeElementValue(covariant MemberElement element) { 109 String computeElementValue(Id id, covariant MemberElement element) {
110 // TODO(johnniwinther,efortuna): Collect data for the member 110 // TODO(johnniwinther,efortuna): Collect data for the member
111 // (has thisLocal, has box, etc.). 111 // (has thisLocal, has box, etc.).
112 return computeObjectValue(element); 112 return computeObjectValue(element);
113 } 113 }
114 } 114 }
115 115
116 /// Kernel IR visitor for computing closure data. 116 /// Kernel IR visitor for computing closure data.
117 class ClosureIrChecker extends IrDataExtractor with ComputeValueMixin<ir.Node> { 117 class ClosureIrChecker extends IrDataExtractor with ComputeValueMixin<ir.Node> {
118 final MemberEntity member; 118 final MemberEntity member;
119 final ClosureDataLookup<ir.Node> closureDataLookup; 119 final ClosureDataLookup<ir.Node> closureDataLookup;
120 final KernelToLocalsMap _localsMap; 120 final KernelToLocalsMap _localsMap;
121 final bool verbose; 121 final bool verbose;
122 122
123 ClosureIrChecker( 123 ClosureIrChecker(
124 DiagnosticReporter reporter,
124 Map<Id, ActualData> actualMap, 125 Map<Id, ActualData> actualMap,
125 KernelToElementMapForBuilding elementMap, 126 KernelToElementMapForBuilding elementMap,
126 this.member, 127 this.member,
127 this._localsMap, 128 this._localsMap,
128 this.closureDataLookup, 129 this.closureDataLookup,
129 {this.verbose: false}) 130 {this.verbose: false})
130 : super(actualMap) { 131 : super(reporter, actualMap) {
131 pushMember(member); 132 pushMember(member);
132 } 133 }
133 134
134 visitFunctionExpression(ir.FunctionExpression node) { 135 visitFunctionExpression(ir.FunctionExpression node) {
135 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node); 136 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node);
136 pushMember(info.callMethod); 137 pushMember(info.callMethod);
137 pushLocalFunction(node); 138 pushLocalFunction(node);
138 super.visitFunctionExpression(node); 139 super.visitFunctionExpression(node);
139 popLocalFunction(); 140 popLocalFunction();
140 popMember(); 141 popMember();
141 } 142 }
142 143
143 visitFunctionDeclaration(ir.FunctionDeclaration node) { 144 visitFunctionDeclaration(ir.FunctionDeclaration node) {
144 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node); 145 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node);
145 pushMember(info.callMethod); 146 pushMember(info.callMethod);
146 pushLocalFunction(node); 147 pushLocalFunction(node);
147 super.visitFunctionDeclaration(node); 148 super.visitFunctionDeclaration(node);
148 popLocalFunction(); 149 popLocalFunction();
149 popMember(); 150 popMember();
150 } 151 }
151 152
152 @override 153 @override
153 String computeNodeValue(ir.Node node) { 154 String computeNodeValue(Id id, ir.Node node) {
154 if (node is ir.VariableDeclaration) { 155 if (node is ir.VariableDeclaration) {
155 if (node.parent is ir.FunctionDeclaration) {
156 ClosureRepresentationInfo info =
157 closureDataLookup.getClosureInfo(node.parent);
158 return computeObjectValue(info.callMethod);
159 }
160 Local local = _localsMap.getLocalVariable(node); 156 Local local = _localsMap.getLocalVariable(node);
161 return computeLocalValue(local); 157 return computeLocalValue(local);
158 } else if (node is ir.FunctionDeclaration) {
159 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node);
160 return computeObjectValue(info.callMethod);
162 } else if (node is ir.FunctionExpression) { 161 } else if (node is ir.FunctionExpression) {
163 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node); 162 ClosureRepresentationInfo info = closureDataLookup.getClosureInfo(node);
164 return computeObjectValue(info.callMethod); 163 return computeObjectValue(info.callMethod);
165 } 164 }
166 return null; 165 return null;
167 } 166 }
168 167
169 @override 168 @override
170 String computeMemberValue(ir.Member node) { 169 String computeMemberValue(Id id, ir.Member node) {
171 return computeObjectValue(member); 170 return computeObjectValue(member);
172 } 171 }
173 } 172 }
174 173
175 abstract class ComputeValueMixin<T> { 174 abstract class ComputeValueMixin<T> {
176 bool get verbose; 175 bool get verbose;
177 Map<BoxLocal, String> boxNames = <BoxLocal, String>{}; 176 Map<BoxLocal, String> boxNames = <BoxLocal, String>{};
178 ClosureDataLookup<T> get closureDataLookup; 177 ClosureDataLookup<T> get closureDataLookup;
179 Link<ScopeInfo> scopeInfoStack = const Link<ScopeInfo>(); 178 Link<ScopeInfo> scopeInfoStack = const Link<ScopeInfo>();
180 ScopeInfo get scopeInfo => scopeInfoStack.head; 179 ScopeInfo get scopeInfo => scopeInfoStack.head;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 if (value != '') { 310 if (value != '') {
312 sb.write('='); 311 sb.write('=');
313 sb.write(value); 312 sb.write(value);
314 } 313 }
315 needsComma = true; 314 needsComma = true;
316 } 315 }
317 } 316 }
318 return sb.toString(); 317 return sb.toString();
319 } 318 }
320 } 319 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/closure/data/captured_variable.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698