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

Side by Side Diff: pkg/analyzer2dart/lib/src/tree_shaker.dart

Issue 652613004: Add tree shaker support for setters and field writes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library analyzer2dart.treeShaker; 5 library analyzer2dart.treeShaker;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/analyzer.dart'; 9 import 'package:analyzer/analyzer.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 for (PropertyAccessorElement accessor in classElement.accessors) { 130 for (PropertyAccessorElement accessor in classElement.accessors) {
131 if (accessor.isGetter && selector.name == accessor.name) { 131 if (accessor.isGetter && selector.name == accessor.name) {
132 if (accessor.isSynthetic) { 132 if (accessor.isSynthetic) {
133 // This accessor is implied by the corresponding field declaration. 133 // This accessor is implied by the corresponding field declaration.
134 fields.add(accessor.variable); 134 fields.add(accessor.variable);
135 } else { 135 } else {
136 accessors.add(accessor); 136 accessors.add(accessor);
137 } 137 }
138 } 138 }
139 } 139 }
140 } else if (selector.kind == SelectorKind.SETTER) {
141 for (PropertyAccessorElement accessor in classElement.accessors) {
142 // accessor.name uses the convention that setter names end in '='.
143 if (accessor.isSetter && '${selector.name}=' == accessor.name) {
scheglov 2014/10/21 14:58:21 We could probably make it slightly faster by compu
Paul Berry 2014/10/21 15:14:04 Done.
144 if (accessor.isSynthetic) {
145 // This accessor is implied by the corresponding field declaration.
146 // TODO(paulberry): should we distinguish reads and writes?
147 fields.add(accessor.variable);
148 } else {
149 accessors.add(accessor);
150 }
151 }
152 }
140 } 153 }
141 } 154 }
142 } 155 }
143 156
144 /** 157 /**
145 * This class is responsible for driving the tree shaking process, and 158 * This class is responsible for driving the tree shaking process, and
146 * and performing the global inferences necessary to determine which methods 159 * and performing the global inferences necessary to determine which methods
147 * in the source program are reachable. It makes use of 160 * in the source program are reachable. It makes use of
148 * [LocalReachabilityComputer] to do local analysis of individual classes and 161 * [LocalReachabilityComputer] to do local analysis of individual classes and
149 * methods. 162 * methods.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // Invocation of a property. TODO(paulberry): handle this. 300 // Invocation of a property. TODO(paulberry): handle this.
288 super.visitStaticPropertyInvocation(node, semantics); 301 super.visitStaticPropertyInvocation(node, semantics);
289 } 302 }
290 303
291 void visitDynamicAccess(AstNode node, AccessSemantics semantics) { 304 void visitDynamicAccess(AstNode node, AccessSemantics semantics) {
292 if (semantics.isRead) { 305 if (semantics.isRead) {
293 analysis.invokes.add( 306 analysis.invokes.add(
294 new Selector.getter(semantics.identifier.name, null)); 307 new Selector.getter(semantics.identifier.name, null));
295 } 308 }
296 if (semantics.isWrite) { 309 if (semantics.isWrite) {
297 // TODO(paulberry): implement. 310 // Selector.setter constructor uses the convention that setter names
298 return giveUp(node, '_handlePropertyAccess of ${semantics}.'); 311 // don't end in '='.
312 analysis.invokes.add(
313 new Selector.setter(semantics.identifier.name, null));
299 } 314 }
300 } 315 }
301 316
302 void visitLocalFunctionAccess(AstNode node, AccessSemantics semantics) { 317 void visitLocalFunctionAccess(AstNode node, AccessSemantics semantics) {
303 // Locals don't need to be tree shaken. 318 // Locals don't need to be tree shaken.
304 } 319 }
305 320
306 void visitLocalVariableAccess(AstNode node, AccessSemantics semantics) { 321 void visitLocalVariableAccess(AstNode node, AccessSemantics semantics) {
307 // Locals don't need to be tree shaken. 322 // Locals don't need to be tree shaken.
308 } 323 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 367
353 @override 368 @override
354 void 369 void
355 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) { 370 visitRedirectingConstructorInvocation(RedirectingConstructorInvocation nod e) {
356 // Note: we don't have to worry about node.staticElement being 371 // Note: we don't have to worry about node.staticElement being
357 // null, because that would have been detected by the analyzer and 372 // null, because that would have been detected by the analyzer and
358 // reported as a compile time error. 373 // reported as a compile time error.
359 analysis.calls.add(node.staticElement); 374 analysis.calls.add(node.staticElement);
360 } 375 }
361 } 376 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer2dart/test/tree_shaker_test.dart » ('j') | pkg/analyzer2dart/test/tree_shaker_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698