OLD | NEW |
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 /// Defines static information collected by the type checker and used later by | 5 /// Defines static information collected by the type checker and used later by |
6 /// emitters to generate code. | 6 /// emitters to generate code. |
7 library dev_compiler.src.info; | 7 library dev_compiler.src.info; |
8 | 8 |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
11 import 'package:analyzer/src/generated/error.dart'; | 11 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/parser.dart'; |
12 | 13 |
13 import 'package:dev_compiler/src/checker/rules.dart'; | 14 import 'package:dev_compiler/src/checker/rules.dart'; |
14 import 'package:dev_compiler/src/utils.dart' as utils; | 15 import 'package:dev_compiler/src/utils.dart' as utils; |
15 | 16 |
16 /// Represents a summary of the results collected by running the program | 17 /// Represents a summary of the results collected by running the program |
17 /// checker. | 18 /// checker. |
18 class CheckerResults { | 19 class CheckerResults { |
19 final List<LibraryInfo> libraries; | 20 final List<LibraryInfo> libraries; |
20 final TypeRules rules; | 21 final TypeRules rules; |
21 final bool failure; | 22 final bool failure; |
(...skipping 24 matching lines...) Expand all Loading... |
46 | 47 |
47 Iterable<CompilationUnit> get libraryThenParts sync* { | 48 Iterable<CompilationUnit> get libraryThenParts sync* { |
48 yield library; | 49 yield library; |
49 yield* parts; | 50 yield* parts; |
50 } | 51 } |
51 | 52 |
52 Iterable<CompilationUnit> get partsThenLibrary sync* { | 53 Iterable<CompilationUnit> get partsThenLibrary sync* { |
53 yield* parts; | 54 yield* parts; |
54 yield library; | 55 yield library; |
55 } | 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 } |
56 } | 94 } |
57 | 95 |
58 // The abstract type of coercions mapping one type to another. | 96 // The abstract type of coercions mapping one type to another. |
59 // This class also exposes static builder functions which | 97 // This class also exposes static builder functions which |
60 // check for errors and reduce redundant coercions to the identity. | 98 // check for errors and reduce redundant coercions to the identity. |
61 abstract class Coercion { | 99 abstract class Coercion { |
62 final DartType fromType; | 100 final DartType fromType; |
63 final DartType toType; | 101 final DartType toType; |
64 Coercion(this.fromType, this.toType); | 102 Coercion(this.fromType, this.toType); |
65 static Coercion cast(DartType fromT, DartType toT) => new Cast(fromT, toT); | 103 static Coercion cast(DartType fromT, DartType toT) => new Cast(fromT, toT); |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 /// Better to have `super` at the end, as required by the Dart style guide: | 572 /// Better to have `super` at the end, as required by the Dart style guide: |
535 /// <http://goo.gl/q1T4BB> | 573 /// <http://goo.gl/q1T4BB> |
536 /// | 574 /// |
537 /// For now this is the only pattern we support. | 575 /// For now this is the only pattern we support. |
538 class InvalidSuperInvocation extends StaticError { | 576 class InvalidSuperInvocation extends StaticError { |
539 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); | 577 InvalidSuperInvocation(SuperConstructorInvocation node) : super(node); |
540 | 578 |
541 @override String get message => "super call must be last in an initializer " | 579 @override String get message => "super call must be last in an initializer " |
542 "list (see http://goo.gl/q1T4BB): {0}"; | 580 "list (see http://goo.gl/q1T4BB): {0}"; |
543 } | 581 } |
OLD | NEW |