Chromium Code Reviews| 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/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 */ | 50 */ |
| 51 final TypeProvider typeProvider; | 51 final TypeProvider typeProvider; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * Indicates whether the summary should be resynthesized assuming strong mode | 54 * Indicates whether the summary should be resynthesized assuming strong mode |
| 55 * semantics. | 55 * semantics. |
| 56 */ | 56 */ |
| 57 final bool strongMode; | 57 final bool strongMode; |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Map of top level elements resynthesized from summaries. The two map | |
|
Paul Berry
2016/02/12 19:32:03
s/top level elements/compilation units/
| |
| 61 * keys are the first two elements of the element's location (the library | |
| 62 * URI and the compilation unit URI). | |
| 63 */ | |
| 64 final Map<String, Map<String, CompilationUnitElement>> _resynthesizedUnits = | |
| 65 <String, Map<String, CompilationUnitElement>>{}; | |
| 66 | |
| 67 /** | |
| 60 * Map of top level elements resynthesized from summaries. The three map | 68 * Map of top level elements resynthesized from summaries. The three map |
| 61 * keys are the first three elements of the element's location (the library | 69 * keys are the first three elements of the element's location (the library |
| 62 * URI, the compilation unit URI, and the name of the top level declaration). | 70 * URI, the compilation unit URI, and the name of the top level declaration). |
| 63 */ | 71 */ |
| 64 final Map<String, Map<String, Map<String, Element>>> _resynthesizedElements = | 72 final Map<String, Map<String, Map<String, Element>>> _resynthesizedElements = |
| 65 <String, Map<String, Map<String, Element>>>{}; | 73 <String, Map<String, Map<String, Element>>>{}; |
| 66 | 74 |
| 67 /** | 75 /** |
| 68 * Map of libraries which have been resynthesized from summaries. The map | 76 * Map of libraries which have been resynthesized from summaries. The map |
| 69 * key is the library URI. | 77 * key is the library URI. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 94 Element getElement(ElementLocation location) { | 102 Element getElement(ElementLocation location) { |
| 95 List<String> components = location.components; | 103 List<String> components = location.components; |
| 96 String libraryUri = components[0]; | 104 String libraryUri = components[0]; |
| 97 // Ask the parent resynthesizer. | 105 // Ask the parent resynthesizer. |
| 98 if (parent != null && parent._hasLibrarySummary(libraryUri)) { | 106 if (parent != null && parent._hasLibrarySummary(libraryUri)) { |
| 99 return parent.getElement(location); | 107 return parent.getElement(location); |
| 100 } | 108 } |
| 101 // Resynthesize locally. | 109 // Resynthesize locally. |
| 102 if (components.length == 1) { | 110 if (components.length == 1) { |
| 103 return getLibraryElement(libraryUri); | 111 return getLibraryElement(libraryUri); |
| 112 } else if (components.length == 2) { | |
| 113 Map<String, CompilationUnitElement> libraryMap = | |
| 114 _resynthesizedUnits[libraryUri]; | |
| 115 if (libraryMap == null) { | |
| 116 getLibraryElement(libraryUri); | |
| 117 libraryMap = _resynthesizedUnits[libraryUri]; | |
| 118 assert(libraryMap != null); | |
| 119 } | |
| 120 String unitUri = components[1]; | |
| 121 CompilationUnitElement element = libraryMap[unitUri]; | |
| 122 if (element == null) { | |
| 123 throw new Exception('Unit element not found in summary: $location'); | |
| 124 } | |
| 125 return element; | |
| 104 } else if (components.length == 3 || components.length == 4) { | 126 } else if (components.length == 3 || components.length == 4) { |
| 105 Map<String, Map<String, Element>> libraryMap = | 127 Map<String, Map<String, Element>> libraryMap = |
| 106 _resynthesizedElements[libraryUri]; | 128 _resynthesizedElements[libraryUri]; |
| 107 if (libraryMap == null) { | 129 if (libraryMap == null) { |
| 108 getLibraryElement(libraryUri); | 130 getLibraryElement(libraryUri); |
| 109 libraryMap = _resynthesizedElements[libraryUri]; | 131 libraryMap = _resynthesizedElements[libraryUri]; |
| 110 assert(libraryMap != null); | 132 assert(libraryMap != null); |
| 111 } | 133 } |
| 112 Map<String, Element> compilationUnitElements = libraryMap[components[1]]; | 134 Map<String, Element> compilationUnitElements = libraryMap[components[1]]; |
| 113 Element element; | 135 Element element; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 ]; | 184 ]; |
| 163 Source librarySource = _getSource(uri); | 185 Source librarySource = _getSource(uri); |
| 164 for (String part in serializedUnits[0].publicNamespace.parts) { | 186 for (String part in serializedUnits[0].publicNamespace.parts) { |
| 165 Source partSource = sourceFactory.resolveUri(librarySource, part); | 187 Source partSource = sourceFactory.resolveUri(librarySource, part); |
| 166 String partAbsUri = partSource.uri.toString(); | 188 String partAbsUri = partSource.uri.toString(); |
| 167 serializedUnits.add(_getUnlinkedSummaryOrThrow(partAbsUri)); | 189 serializedUnits.add(_getUnlinkedSummaryOrThrow(partAbsUri)); |
| 168 } | 190 } |
| 169 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( | 191 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( |
| 170 this, serializedLibrary, serializedUnits, librarySource); | 192 this, serializedLibrary, serializedUnits, librarySource); |
| 171 LibraryElement library = libraryResynthesizer.buildLibrary(); | 193 LibraryElement library = libraryResynthesizer.buildLibrary(); |
| 172 _resynthesizedElements[uri] = libraryResynthesizer.resummarizedElements; | 194 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits; |
| 195 _resynthesizedElements[uri] = libraryResynthesizer.resynthesizedElements; | |
| 173 return library; | 196 return library; |
| 174 }); | 197 }); |
| 175 } | 198 } |
| 176 | 199 |
| 177 /** | 200 /** |
| 178 * Return the [LinkedLibrary] for the given [uri] or `null` if it could not | 201 * Return the [LinkedLibrary] for the given [uri] or `null` if it could not |
| 179 * be found. Caller has already checked that `parent.hasLibrarySummary(uri)` | 202 * be found. Caller has already checked that `parent.hasLibrarySummary(uri)` |
| 180 * returns `false`. | 203 * returns `false`. |
| 181 */ | 204 */ |
| 182 LinkedLibrary getLinkedSummary(String uri); | 205 LinkedLibrary getLinkedSummary(String uri); |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 */ | 716 */ |
| 694 CompilationUnitElementImpl currentCompilationUnit; | 717 CompilationUnitElementImpl currentCompilationUnit; |
| 695 | 718 |
| 696 /** | 719 /** |
| 697 * The [ConstructorElementImpl] for the constructor currently being | 720 * The [ConstructorElementImpl] for the constructor currently being |
| 698 * resynthesized. | 721 * resynthesized. |
| 699 */ | 722 */ |
| 700 ConstructorElementImpl currentConstructor; | 723 ConstructorElementImpl currentConstructor; |
| 701 | 724 |
| 702 /** | 725 /** |
| 726 * Map of compilation unit elements that have been resynthesized so far. The | |
| 727 * key is the URI of the compilation unit. | |
| 728 */ | |
| 729 final Map<String, CompilationUnitElement> resynthesizedUnits = | |
| 730 <String, CompilationUnitElement>{}; | |
| 731 | |
| 732 /** | |
| 703 * Map of top level elements that have been resynthesized so far. The first | 733 * Map of top level elements that have been resynthesized so far. The first |
| 704 * key is the URI of the compilation unit; the second is the name of the top | 734 * key is the URI of the compilation unit; the second is the name of the top |
| 705 * level element. | 735 * level element. |
| 706 */ | 736 */ |
| 707 final Map<String, Map<String, Element>> resummarizedElements = | 737 final Map<String, Map<String, Element>> resynthesizedElements = |
| 708 <String, Map<String, Element>>{}; | 738 <String, Map<String, Element>>{}; |
| 709 | 739 |
| 710 /** | 740 /** |
| 711 * Type parameters for the generic class, typedef, or executable currently | 741 * Type parameters for the generic class, typedef, or executable currently |
| 712 * being resynthesized, if any. If multiple entities with type parameters | 742 * being resynthesized, if any. If multiple entities with type parameters |
| 713 * are nested (e.g. a generic executable inside a generic class), this is the | 743 * are nested (e.g. a generic executable inside a generic class), this is the |
| 714 * concatenation of all type parameters from all declarations currently in | 744 * concatenation of all type parameters from all declarations currently in |
| 715 * force, with the outermost declaration appearing first. If there are no | 745 * force, with the outermost declaration appearing first. If there are no |
| 716 * type parameters, or we are not currently resynthesizing a class, typedef, | 746 * type parameters, or we are not currently resynthesizing a class, typedef, |
| 717 * or executable, then this is an empty list. | 747 * or executable, then this is an empty list. |
| (...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1880 } | 1910 } |
| 1881 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { | 1911 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { |
| 1882 elementMap[typeAlias.name] = typeAlias; | 1912 elementMap[typeAlias.name] = typeAlias; |
| 1883 } | 1913 } |
| 1884 for (FunctionElement function in unit.functions) { | 1914 for (FunctionElement function in unit.functions) { |
| 1885 elementMap[function.name] = function; | 1915 elementMap[function.name] = function; |
| 1886 } | 1916 } |
| 1887 for (PropertyAccessorElementImpl accessor in unit.accessors) { | 1917 for (PropertyAccessorElementImpl accessor in unit.accessors) { |
| 1888 elementMap[accessor.identifier] = accessor; | 1918 elementMap[accessor.identifier] = accessor; |
| 1889 } | 1919 } |
| 1890 resummarizedElements[absoluteUri] = elementMap; | 1920 resynthesizedUnits[absoluteUri] = unit; |
| 1921 resynthesizedElements[absoluteUri] = elementMap; | |
| 1891 } | 1922 } |
| 1892 | 1923 |
| 1893 /** | 1924 /** |
| 1894 * Set up data structures for deserializing a compilation unit. | 1925 * Set up data structures for deserializing a compilation unit. |
| 1895 */ | 1926 */ |
| 1896 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { | 1927 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { |
| 1897 linkedUnit = linkedLibrary.units[unitNum]; | 1928 linkedUnit = linkedLibrary.units[unitNum]; |
| 1898 unlinkedUnit = unlinkedUnits[unitNum]; | 1929 unlinkedUnit = unlinkedUnits[unitNum]; |
| 1899 linkedTypeMap = <int, EntityRef>{}; | 1930 linkedTypeMap = <int, EntityRef>{}; |
| 1900 currentCompilationUnit = unit; | 1931 currentCompilationUnit = unit; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2117 } | 2148 } |
| 2118 : () => this.element; | 2149 : () => this.element; |
| 2119 // TODO(paulberry): Is it a bug that we have to pass `false` for | 2150 // TODO(paulberry): Is it a bug that we have to pass `false` for |
| 2120 // isInstantiated? | 2151 // isInstantiated? |
| 2121 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); | 2152 return new DeferredFunctionTypeImpl(computer, null, typeArguments, false); |
| 2122 } else { | 2153 } else { |
| 2123 return null; | 2154 return null; |
| 2124 } | 2155 } |
| 2125 } | 2156 } |
| 2126 } | 2157 } |
| OLD | NEW |