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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1768713002: Fixes to associating existing elements with an AST (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Clean up Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.src.task.dart; 5 library analyzer.src.task.dart;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME); 997 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME);
998 Map<Source, LibraryElement> importLibraryMap = 998 Map<Source, LibraryElement> importLibraryMap =
999 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME); 999 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME);
1000 Map<Source, LibraryElement> exportLibraryMap = 1000 Map<Source, LibraryElement> exportLibraryMap =
1001 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME); 1001 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME);
1002 Map<Source, SourceKind> importSourceKindMap = 1002 Map<Source, SourceKind> importSourceKindMap =
1003 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME); 1003 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME);
1004 Map<Source, SourceKind> exportSourceKindMap = 1004 Map<Source, SourceKind> exportSourceKindMap =
1005 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME); 1005 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
1006 // 1006 //
1007 // Build elements. 1007 // Try to get the existing LibraryElement.
1008 // 1008 //
1009 DirectiveElementBuilder builder = new DirectiveElementBuilder( 1009 LibraryElement element;
1010 context, 1010 {
1011 libraryElement, 1011 InternalAnalysisContext internalContext =
1012 importLibraryMap, 1012 context as InternalAnalysisContext;
1013 importSourceKindMap, 1013 AnalysisCache analysisCache = internalContext.analysisCache;
1014 exportLibraryMap, 1014 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
1015 exportSourceKindMap); 1015 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
1016 libraryUnit.accept(builder); 1016 if (element == null &&
1017 // See commentary in the computation of the LIBRARY_CYCLE result 1017 internalContext.aboutToComputeResult(
1018 // for details on library cycle invalidation. 1018 cacheEntry, COMPILATION_UNIT_ELEMENT)) {
scheglov 2016/03/04 21:49:30 LIBRARY_ELEMENT2
Brian Wilkerson 2016/03/07 16:20:28 Good catch! Done.
1019 libraryElement.invalidateLibraryCycles(); 1019 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
1020 }
1021 }
1022 //
1023 // Build or reuse the directive elements.
1024 //
1025 List<AnalysisError> errors;
1026 if (element == null) {
1027 DirectiveElementBuilder builder = new DirectiveElementBuilder(
1028 context,
1029 libraryElement,
1030 importLibraryMap,
1031 importSourceKindMap,
1032 exportLibraryMap,
1033 exportSourceKindMap);
1034 libraryUnit.accept(builder);
1035 // See the commentary in the computation of the LIBRARY_CYCLE result
1036 // for details on library cycle invalidation.
1037 libraryElement.invalidateLibraryCycles();
1038 errors = builder.errors;
1039 } else {
1040 DirectiveResolver resolver = new DirectiveResolver();
1041 libraryUnit.accept(resolver);
1042 }
1020 // 1043 //
1021 // Record outputs. 1044 // Record outputs.
1022 // 1045 //
1023 outputs[LIBRARY_ELEMENT2] = libraryElement; 1046 outputs[LIBRARY_ELEMENT2] = libraryElement;
1024 outputs[BUILD_DIRECTIVES_ERRORS] = builder.errors; 1047 outputs[BUILD_DIRECTIVES_ERRORS] = errors;
1025 } 1048 }
1026 1049
1027 /** 1050 /**
1028 * Return a map from the names of the inputs of this kind of task to the task 1051 * Return a map from the names of the inputs of this kind of task to the task
1029 * input descriptors describing those inputs for a task with the 1052 * input descriptors describing those inputs for a task with the
1030 * given library [libSource]. 1053 * given library [libSource].
1031 */ 1054 */
1032 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1055 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1033 Source source = target; 1056 Source source = target;
1034 return <String, TaskInput>{ 1057 return <String, TaskInput>{
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 } 1399 }
1377 // 1400 //
1378 // Create a new LibraryElement. 1401 // Create a new LibraryElement.
1379 // 1402 //
1380 if (libraryElement == null) { 1403 if (libraryElement == null) {
1381 libraryElement = 1404 libraryElement =
1382 new LibraryElementImpl.forNode(owningContext, libraryNameNode); 1405 new LibraryElementImpl.forNode(owningContext, libraryNameNode);
1383 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1406 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1384 libraryElement.entryPoint = entryPoint; 1407 libraryElement.entryPoint = entryPoint;
1385 libraryElement.parts = sourcedCompilationUnits; 1408 libraryElement.parts = sourcedCompilationUnits;
1386 for (Directive directive in directivesToResolve) { 1409 libraryElement.hasExtUri = _hasExtUri(definingCompilationUnit);
1387 directive.element = libraryElement;
1388 }
1389 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement); 1410 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement);
1390 // set the library documentation to the docs associated with the first 1411 // set the library documentation to the docs associated with the first
1391 // directive in the compilation unit. 1412 // directive in the compilation unit.
1392 if (definingCompilationUnit.directives.isNotEmpty) { 1413 if (definingCompilationUnit.directives.isNotEmpty) {
1393 setElementDocumentationComment( 1414 setElementDocumentationComment(
1394 libraryElement, definingCompilationUnit.directives.first); 1415 libraryElement, definingCompilationUnit.directives.first);
1395 } 1416 }
1396 } 1417 }
1397 // 1418 //
1419 // Resolve the relevant directives to the library element.
1420 //
1421 // TODO(brianwilkerson) This updates the state of the AST structures but
1422 // does not associate a new result with it.
1423 //
1424 for (Directive directive in directivesToResolve) {
1425 directive.element = libraryElement;
1426 }
1427 //
1398 // Record outputs. 1428 // Record outputs.
1399 // 1429 //
1400 outputs[BUILD_LIBRARY_ERRORS] = errors; 1430 outputs[BUILD_LIBRARY_ERRORS] = errors;
1401 outputs[LIBRARY_ELEMENT1] = libraryElement; 1431 outputs[LIBRARY_ELEMENT1] = libraryElement;
1402 outputs[IS_LAUNCHABLE] = entryPoint != null; 1432 outputs[IS_LAUNCHABLE] = entryPoint != null;
1403 } 1433 }
1404 1434
1405 /** 1435 /**
1406 * Return the top-level [FunctionElement] entry point, or `null` if the given 1436 * Return the top-level [FunctionElement] entry point, or `null` if the given
1407 * [element] does not define an entry point. 1437 * [element] does not define an entry point.
(...skipping 19 matching lines...) Expand all
1427 LibraryIdentifier libraryName = directive.libraryName; 1457 LibraryIdentifier libraryName = directive.libraryName;
1428 if (libraryName != null) { 1458 if (libraryName != null) {
1429 return libraryName.name; 1459 return libraryName.name;
1430 } 1460 }
1431 } 1461 }
1432 } 1462 }
1433 return null; 1463 return null;
1434 } 1464 }
1435 1465
1436 /** 1466 /**
1467 * Return `true` if the given compilation [unit] contains at least one
1468 * import directive with a `dart-ext:` URI.
1469 */
1470 bool _hasExtUri(CompilationUnit unit) {
1471 for (Directive directive in unit.directives) {
1472 if (directive is ImportDirective) {
1473 if (DartUriResolver.isDartExtUri(directive.uriContent)) {
1474 return true;
1475 }
1476 }
1477 }
1478 return false;
1479 }
1480
1481 /**
1437 * Return a map from the names of the inputs of this kind of task to the task 1482 * Return a map from the names of the inputs of this kind of task to the task
1438 * input descriptors describing those inputs for a task with the given 1483 * input descriptors describing those inputs for a task with the given
1439 * [libSource]. 1484 * [libSource].
1440 */ 1485 */
1441 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1486 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1442 Source source = target; 1487 Source source = target;
1443 return <String, TaskInput>{ 1488 return <String, TaskInput>{
1444 DEFINING_UNIT_INPUT: 1489 DEFINING_UNIT_INPUT:
1445 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), 1490 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)),
1446 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) { 1491 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) {
(...skipping 3811 matching lines...) Expand 10 before | Expand all | Expand 10 after
5258 5303
5259 @override 5304 @override
5260 bool moveNext() { 5305 bool moveNext() {
5261 if (_newSources.isEmpty) { 5306 if (_newSources.isEmpty) {
5262 return false; 5307 return false;
5263 } 5308 }
5264 currentTarget = _newSources.removeLast(); 5309 currentTarget = _newSources.removeLast();
5265 return true; 5310 return true;
5266 } 5311 }
5267 } 5312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698