| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /// Defines static information collected by the type checker and used later by | |
| 6 /// emitters to generate code. | |
| 7 | |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | |
| 9 import 'package:analyzer/src/dart/ast/ast.dart'; | |
| 10 import 'package:analyzer/src/dart/ast/utilities.dart'; | |
| 11 import 'package:analyzer/src/generated/element.dart'; | |
| 12 import 'package:analyzer/src/generated/parser.dart'; | |
| 13 | |
| 14 import 'utils.dart' as utils; | |
| 15 import 'package:analyzer/src/task/strong/info.dart'; | |
| 16 export 'package:analyzer/src/task/strong/info.dart'; | |
| 17 | |
| 18 /// Represents a summary of the results collected by running the program | |
| 19 /// checker. | |
| 20 class CheckerResults { | |
| 21 final List<LibraryInfo> libraries; | |
| 22 final bool failure; | |
| 23 | |
| 24 CheckerResults(this.libraries, this.failure); | |
| 25 } | |
| 26 | |
| 27 /// Computed information about each library. | |
| 28 class LibraryInfo { | |
| 29 /// Canonical name of the library. This is unfortunately not derived from the | |
| 30 /// library directive as it doesn't have any meaningful rules enforced. | |
| 31 /// Instead, this is inferred from the path to the file defining the library. | |
| 32 final String name; | |
| 33 | |
| 34 /// Corresponding analyzer element. | |
| 35 final LibraryElement library; | |
| 36 | |
| 37 LibraryInfo(library) | |
| 38 : library = library, | |
| 39 name = utils.canonicalLibraryName(library); | |
| 40 } | |
| 41 | |
| 42 class LibraryUnit { | |
| 43 final CompilationUnit library; | |
| 44 final List<CompilationUnit> parts; | |
| 45 | |
| 46 LibraryUnit(this.library, this.parts); | |
| 47 | |
| 48 Iterable<CompilationUnit> get libraryThenParts sync* { | |
| 49 yield library; | |
| 50 yield* parts; | |
| 51 } | |
| 52 | |
| 53 Iterable<CompilationUnit> get partsThenLibrary sync* { | |
| 54 yield* parts; | |
| 55 yield library; | |
| 56 } | |
| 57 | |
| 58 /// Creates a clone of this library's AST. | |
| 59 LibraryUnit clone() { | |
| 60 return new LibraryUnit( | |
| 61 _cloneUnit(library), parts.map(_cloneUnit).toList(growable: false)); | |
| 62 } | |
| 63 | |
| 64 static CompilationUnit _cloneUnit(CompilationUnit oldNode) { | |
| 65 var newNode = oldNode.accept(new _AstCloner()); | |
| 66 ResolutionCopier.copyResolutionData(oldNode, newNode); | |
| 67 return newNode; | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 class _AstCloner extends AstCloner { | |
| 72 void _cloneProperties(AstNode clone, AstNode node) { | |
| 73 if (clone != null) { | |
| 74 CoercionInfo.set(clone, CoercionInfo.get(node)); | |
| 75 DynamicInvoke.set(clone, DynamicInvoke.get(node)); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 @override | |
| 80 AstNode cloneNode(AstNode node) { | |
| 81 var clone = super.cloneNode(node); | |
| 82 _cloneProperties(clone, node); | |
| 83 return clone; | |
| 84 } | |
| 85 | |
| 86 @override | |
| 87 List cloneNodeList(List list) { | |
| 88 var clone = super.cloneNodeList(list); | |
| 89 for (int i = 0, len = list.length; i < len; i++) { | |
| 90 _cloneProperties(clone[i], list[i]); | |
| 91 } | |
| 92 return clone; | |
| 93 } | |
| 94 | |
| 95 // TODO(jmesserly): ResolutionCopier is not copying this yet. | |
| 96 @override | |
| 97 BlockFunctionBody visitBlockFunctionBody(BlockFunctionBody node) { | |
| 98 var clone = super.visitBlockFunctionBody(node); | |
| 99 (clone as FunctionBodyImpl).localVariableInfo = | |
| 100 (node as FunctionBodyImpl).localVariableInfo; | |
| 101 return clone; | |
| 102 } | |
| 103 | |
| 104 @override | |
| 105 ExpressionFunctionBody visitExpressionFunctionBody( | |
| 106 ExpressionFunctionBody node) { | |
| 107 var clone = super.visitExpressionFunctionBody(node); | |
| 108 (clone as FunctionBodyImpl).localVariableInfo = | |
| 109 (node as FunctionBodyImpl).localVariableInfo; | |
| 110 return clone; | |
| 111 } | |
| 112 } | |
| OLD | NEW |