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 library summary_resynthesizer; | 5 library summary_resynthesizer; |
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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 */ | 838 */ |
839 UnlinkedUnit unlinkedUnit; | 839 UnlinkedUnit unlinkedUnit; |
840 | 840 |
841 /** | 841 /** |
842 * Map from slot id to the corresponding [EntityRef] object for linked types | 842 * Map from slot id to the corresponding [EntityRef] object for linked types |
843 * (i.e. propagated and inferred types). | 843 * (i.e. propagated and inferred types). |
844 */ | 844 */ |
845 Map<int, EntityRef> linkedTypeMap; | 845 Map<int, EntityRef> linkedTypeMap; |
846 | 846 |
847 /** | 847 /** |
| 848 * Set of slot ids corresponding to const constructors that are part of |
| 849 * cycles. |
| 850 */ |
| 851 Set<int> constCycles; |
| 852 |
| 853 /** |
848 * The [CompilationUnitElementImpl] for the compilation unit currently being | 854 * The [CompilationUnitElementImpl] for the compilation unit currently being |
849 * resynthesized. | 855 * resynthesized. |
850 */ | 856 */ |
851 CompilationUnitElementImpl currentCompilationUnit; | 857 CompilationUnitElementImpl currentCompilationUnit; |
852 | 858 |
853 /** | 859 /** |
854 * The [ConstructorElementImpl] for the constructor currently being | 860 * The [ConstructorElementImpl] for the constructor currently being |
855 * resynthesized. | 861 * resynthesized. |
856 */ | 862 */ |
857 ConstructorElementImpl currentConstructor; | 863 ConstructorElementImpl currentConstructor; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 /** | 1075 /** |
1070 * Resynthesize a [ConstructorElement] and place it in the given [holder]. | 1076 * Resynthesize a [ConstructorElement] and place it in the given [holder]. |
1071 * [classType] is the type of the class for which this element is a | 1077 * [classType] is the type of the class for which this element is a |
1072 * constructor. | 1078 * constructor. |
1073 */ | 1079 */ |
1074 void buildConstructor(UnlinkedExecutable serializedExecutable, | 1080 void buildConstructor(UnlinkedExecutable serializedExecutable, |
1075 ElementHolder holder, InterfaceType classType) { | 1081 ElementHolder holder, InterfaceType classType) { |
1076 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); | 1082 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor); |
1077 currentConstructor = new ConstructorElementImpl( | 1083 currentConstructor = new ConstructorElementImpl( |
1078 serializedExecutable.name, serializedExecutable.nameOffset); | 1084 serializedExecutable.name, serializedExecutable.nameOffset); |
| 1085 currentConstructor.isCycleFree = serializedExecutable.isConst && |
| 1086 !constCycles.contains(serializedExecutable.constCycleSlot); |
1079 if (serializedExecutable.name.isEmpty) { | 1087 if (serializedExecutable.name.isEmpty) { |
1080 currentConstructor.nameEnd = | 1088 currentConstructor.nameEnd = |
1081 serializedExecutable.nameOffset + classType.name.length; | 1089 serializedExecutable.nameOffset + classType.name.length; |
1082 } else { | 1090 } else { |
1083 currentConstructor.nameEnd = serializedExecutable.nameEnd; | 1091 currentConstructor.nameEnd = serializedExecutable.nameEnd; |
1084 currentConstructor.periodOffset = serializedExecutable.periodOffset; | 1092 currentConstructor.periodOffset = serializedExecutable.periodOffset; |
1085 } | 1093 } |
1086 constructors[serializedExecutable.name] = currentConstructor; | 1094 constructors[serializedExecutable.name] = currentConstructor; |
1087 currentConstructor.returnType = classType; | 1095 currentConstructor.returnType = classType; |
1088 buildExecutableCommonParts(currentConstructor, serializedExecutable); | 1096 buildExecutableCommonParts(currentConstructor, serializedExecutable); |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 | 1962 |
1955 /** | 1963 /** |
1956 * Tear down data structures used during deserialization of a compilation | 1964 * Tear down data structures used during deserialization of a compilation |
1957 * unit. | 1965 * unit. |
1958 */ | 1966 */ |
1959 void finishUnit() { | 1967 void finishUnit() { |
1960 unitHolder = null; | 1968 unitHolder = null; |
1961 linkedUnit = null; | 1969 linkedUnit = null; |
1962 unlinkedUnit = null; | 1970 unlinkedUnit = null; |
1963 linkedTypeMap = null; | 1971 linkedTypeMap = null; |
| 1972 constCycles = null; |
1964 referenceInfos = null; | 1973 referenceInfos = null; |
1965 currentCompilationUnit = null; | 1974 currentCompilationUnit = null; |
1966 } | 1975 } |
1967 | 1976 |
1968 /** | 1977 /** |
1969 * Return a list of type arguments corresponding to [currentTypeParameters], | 1978 * Return a list of type arguments corresponding to [currentTypeParameters], |
1970 * skipping the innermost [skipLevels] nesting levels. | 1979 * skipping the innermost [skipLevels] nesting levels. |
1971 * | 1980 * |
1972 * Type parameters are listed in nesting order from innermost to outermost, | 1981 * Type parameters are listed in nesting order from innermost to outermost, |
1973 * and then in declaration order. So for instance if we are resynthesizing a | 1982 * and then in declaration order. So for instance if we are resynthesizing a |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 * Set up data structures for deserializing a compilation unit. | 2213 * Set up data structures for deserializing a compilation unit. |
2205 */ | 2214 */ |
2206 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { | 2215 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { |
2207 linkedUnit = linkedLibrary.units[unitNum]; | 2216 linkedUnit = linkedLibrary.units[unitNum]; |
2208 unlinkedUnit = unlinkedUnits[unitNum]; | 2217 unlinkedUnit = unlinkedUnits[unitNum]; |
2209 linkedTypeMap = <int, EntityRef>{}; | 2218 linkedTypeMap = <int, EntityRef>{}; |
2210 currentCompilationUnit = unit; | 2219 currentCompilationUnit = unit; |
2211 for (EntityRef t in linkedUnit.types) { | 2220 for (EntityRef t in linkedUnit.types) { |
2212 linkedTypeMap[t.slot] = t; | 2221 linkedTypeMap[t.slot] = t; |
2213 } | 2222 } |
| 2223 constCycles = linkedUnit.constCycles.toSet(); |
2214 populateReferenceInfos(); | 2224 populateReferenceInfos(); |
2215 unitHolder = new ElementHolder(); | 2225 unitHolder = new ElementHolder(); |
2216 } | 2226 } |
2217 | 2227 |
2218 /** | 2228 /** |
2219 * Constructor initializers can reference fields and other constructors of | 2229 * Constructor initializers can reference fields and other constructors of |
2220 * the same class, including forward references. So, we need to delay | 2230 * the same class, including forward references. So, we need to delay |
2221 * resolution until after class elements are built. | 2231 * resolution until after class elements are built. |
2222 */ | 2232 */ |
2223 void resolveConstructorInitializers(ClassElementImpl classElement) { | 2233 void resolveConstructorInitializers(ClassElementImpl classElement) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2447 List<DartType> typeArguments = const <DartType>[]; | 2457 List<DartType> typeArguments = const <DartType>[]; |
2448 if (numTypeArguments != 0) { | 2458 if (numTypeArguments != 0) { |
2449 typeArguments = <DartType>[]; | 2459 typeArguments = <DartType>[]; |
2450 for (int i = 0; i < numTypeArguments; i++) { | 2460 for (int i = 0; i < numTypeArguments; i++) { |
2451 typeArguments.add(getTypeArgument(i)); | 2461 typeArguments.add(getTypeArgument(i)); |
2452 } | 2462 } |
2453 } | 2463 } |
2454 return typeArguments; | 2464 return typeArguments; |
2455 } | 2465 } |
2456 } | 2466 } |
OLD | NEW |