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

Side by Side Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1410573005: Memory leak fix. Use correct analysis context for annotation constants. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month 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 | pkg/analyzer/test/generated/all_the_rest_test.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) 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 engine.constant; 5 library engine.constant;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/utilities_general.dart'; 10 import 'package:analyzer/src/generated/utilities_general.dart';
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 /** 1227 /**
1228 * True if instance variables marked as "final" should be treated as "const". 1228 * True if instance variables marked as "final" should be treated as "const".
1229 */ 1229 */
1230 bool treatFinalInstanceVarAsConst = false; 1230 bool treatFinalInstanceVarAsConst = false;
1231 1231
1232 ConstantFinder(this.context, this.source, this.librarySource); 1232 ConstantFinder(this.context, this.source, this.librarySource);
1233 1233
1234 @override 1234 @override
1235 Object visitAnnotation(Annotation node) { 1235 Object visitAnnotation(Annotation node) {
1236 super.visitAnnotation(node); 1236 super.visitAnnotation(node);
1237 AnalysisContext owningContext = _getOwningContext();
1237 constantsToCompute.add(new ConstantEvaluationTarget_Annotation( 1238 constantsToCompute.add(new ConstantEvaluationTarget_Annotation(
1238 context, source, librarySource, node)); 1239 owningContext, source, librarySource, node));
1239 return null; 1240 return null;
1240 } 1241 }
1241 1242
1242 @override 1243 @override
1243 Object visitClassDeclaration(ClassDeclaration node) { 1244 Object visitClassDeclaration(ClassDeclaration node) {
1244 bool prevTreatFinalInstanceVarAsConst = treatFinalInstanceVarAsConst; 1245 bool prevTreatFinalInstanceVarAsConst = treatFinalInstanceVarAsConst;
1245 if (node.element.constructors.any((ConstructorElement e) => e.isConst)) { 1246 if (node.element.constructors.any((ConstructorElement e) => e.isConst)) {
1246 // Instance vars marked "final" need to be included in the dependency 1247 // Instance vars marked "final" need to be included in the dependency
1247 // graph, since constant constructors implicitly use the values in their 1248 // graph, since constant constructors implicitly use the values in their
1248 // initializers. 1249 // initializers.
(...skipping 29 matching lines...) Expand all
1278 treatFinalInstanceVarAsConst && 1279 treatFinalInstanceVarAsConst &&
1279 element is FieldElement && 1280 element is FieldElement &&
1280 node.isFinal && 1281 node.isFinal &&
1281 !element.isStatic)) { 1282 !element.isStatic)) {
1282 if (node.element != null) { 1283 if (node.element != null) {
1283 constantsToCompute.add(node.element); 1284 constantsToCompute.add(node.element);
1284 } 1285 }
1285 } 1286 }
1286 return null; 1287 return null;
1287 } 1288 }
1289
1290 AnalysisContext _getOwningContext() {
1291 if (context is InternalAnalysisContext) {
1292 InternalAnalysisContext internalContext = context;
1293 return internalContext.getContextFor(librarySource);
1294 }
1295 return context;
1296 }
1288 } 1297 }
1289 1298
1290 /** 1299 /**
1291 * An object used to compute the values of constant variables and constant 1300 * An object used to compute the values of constant variables and constant
1292 * constructor invocations in one or more compilation units. The expected usage 1301 * constructor invocations in one or more compilation units. The expected usage
1293 * pattern is for the compilation units to be added to this computer using the 1302 * pattern is for the compilation units to be added to this computer using the
1294 * method [add] and then for the method [computeValues] to be invoked exactly 1303 * method [add] and then for the method [computeValues] to be invoked exactly
1295 * once. Any use of an instance after invoking the method [computeValues] will 1304 * once. Any use of an instance after invoking the method [computeValues] will
1296 * result in unpredictable behavior. 1305 * result in unpredictable behavior.
1297 */ 1306 */
(...skipping 4252 matching lines...) Expand 10 before | Expand all | Expand 10 after
5550 return BoolState.from(_element == rightElement); 5559 return BoolState.from(_element == rightElement);
5551 } else if (rightOperand is DynamicState) { 5560 } else if (rightOperand is DynamicState) {
5552 return BoolState.UNKNOWN_VALUE; 5561 return BoolState.UNKNOWN_VALUE;
5553 } 5562 }
5554 return BoolState.FALSE_STATE; 5563 return BoolState.FALSE_STATE;
5555 } 5564 }
5556 5565
5557 @override 5566 @override
5558 String toString() => _element == null ? "-unknown-" : _element.name; 5567 String toString() => _element == null ? "-unknown-" : _element.name;
5559 } 5568 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698