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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1835313002: Fix AST summarization when there are explicit calls to super constructors. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 | pkg/analyzer/test/src/summary/summary_common.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 563 }
564 } else if (unlinkedExecutable.isFactory) { 564 } else if (unlinkedExecutable.isFactory) {
565 // Factory constructor, but getConstRedirectedConstructor returned 565 // Factory constructor, but getConstRedirectedConstructor returned
566 // null. This can happen if we're visiting one of the special external 566 // null. This can happen if we're visiting one of the special external
567 // const factory constructors in the SDK, or if the code contains 567 // const factory constructors in the SDK, or if the code contains
568 // errors (such as delegating to a non-const constructor, or delegating 568 // errors (such as delegating to a non-const constructor, or delegating
569 // to a constructor that can't be resolved). In any of these cases, 569 // to a constructor that can't be resolved). In any of these cases,
570 // we'll evaluate calls to this constructor without having to refer to 570 // we'll evaluate calls to this constructor without having to refer to
571 // any other constants. So we don't need to report any dependencies. 571 // any other constants. So we don't need to report any dependencies.
572 } else { 572 } else {
573 ClassElementForLink superClass = enclosingClass.supertype?.element;
573 bool superInvocationFound = false; 574 bool superInvocationFound = false;
574 for (UnlinkedConstructorInitializer constructorInitializer 575 for (UnlinkedConstructorInitializer constructorInitializer
575 in constructorElement._unlinkedExecutable.constantInitializers) { 576 in constructorElement._unlinkedExecutable.constantInitializers) {
576 if (constructorInitializer.kind == 577 if (constructorInitializer.kind ==
577 UnlinkedConstructorInitializerKind.superInvocation) { 578 UnlinkedConstructorInitializerKind.superInvocation) {
578 superInvocationFound = true; 579 superInvocationFound = true;
580 if (superClass != null && !superClass.isObject) {
581 ConstructorElementForLink constructor = superClass
582 .getContainedName(constructorInitializer.name)
583 .asConstructor;
584 safeAddDependency(constructor?._constNode);
585 }
579 } 586 }
580 CompilationUnitElementForLink compilationUnit = 587 CompilationUnitElementForLink compilationUnit =
581 constructorElement.enclosingElement.enclosingElement; 588 constructorElement.enclosingElement.enclosingElement;
582 collectDependencies( 589 collectDependencies(
583 dependencies, constructorInitializer.expression, compilationUnit); 590 dependencies, constructorInitializer.expression, compilationUnit);
584 constructorInitializer.arguments.map((UnlinkedConst unlinkedConst) => 591 constructorInitializer.arguments.map((UnlinkedConst unlinkedConst) =>
585 collectDependencies(dependencies, unlinkedConst, compilationUnit)); 592 collectDependencies(dependencies, unlinkedConst, compilationUnit));
586 } 593 }
587 594
588 if (!superInvocationFound) { 595 if (!superInvocationFound) {
589 // No explicit superconstructor invocation found, so we need to 596 // No explicit superconstructor invocation found, so we need to
590 // manually insert a reference to the implicit superconstructor. 597 // manually insert a reference to the implicit superconstructor.
591 ClassElementForLink superClass = enclosingClass.supertype?.element;
592 if (superClass != null && !superClass.isObject) { 598 if (superClass != null && !superClass.isObject) {
593 ConstructorElementForLink unnamedConstructor = 599 ConstructorElementForLink unnamedConstructor =
594 superClass.unnamedConstructor; 600 superClass.unnamedConstructor;
595 safeAddDependency(unnamedConstructor?._constNode); 601 safeAddDependency(unnamedConstructor?._constNode);
596 } 602 }
597 } 603 }
598 for (FieldElementForLink field in enclosingClass.fields) { 604 for (FieldElementForLink field in enclosingClass.fields) {
599 // Note: non-static const isn't allowed but we handle it anyway so 605 // Note: non-static const isn't allowed but we handle it anyway so
600 // that we won't be confused by incorrect code. 606 // that we won't be confused by incorrect code.
601 if ((field.isFinal || field.isConst) && !field.isStatic) { 607 if ((field.isFinal || field.isConst) && !field.isStatic) {
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 1503
1498 /** 1504 /**
1499 * Throw away any information produced by a previous call to [link]. 1505 * Throw away any information produced by a previous call to [link].
1500 */ 1506 */
1501 void unlink() { 1507 void unlink() {
1502 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { 1508 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) {
1503 library.unlink(); 1509 library.unlink();
1504 } 1510 }
1505 } 1511 }
1506 } 1512 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698