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

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

Issue 1633863002: Support for constructor references in constant serializer and prelinker. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
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 import 'package:analyzer/src/summary/format.dart'; 5 import 'package:analyzer/src/summary/format.dart';
6 import 'package:analyzer/src/summary/name_filter.dart'; 6 import 'package:analyzer/src/summary/name_filter.dart';
7 7
8 /** 8 /**
9 * Create a [LinkedLibraryBuilder] corresponding to the given 9 * Create a [LinkedLibraryBuilder] corresponding to the given
10 * [definingUnit], which should be the defining compilation unit for a library. 10 * [definingUnit], which should be the defining compilation unit for a library.
(...skipping 14 matching lines...) Expand all
25 * the transitive closure of parts and exports reachable from those libraries). 25 * the transitive closure of parts and exports reachable from those libraries).
26 * [relativeUri] should be interpreted relative to the defining compilation 26 * [relativeUri] should be interpreted relative to the defining compilation
27 * unit of the library being prelinked. 27 * unit of the library being prelinked.
28 * 28 *
29 * If no file exists at the given uri, `null` should be returned. 29 * If no file exists at the given uri, `null` should be returned.
30 */ 30 */
31 typedef UnlinkedPublicNamespace GetImportCallback(String relativeUri); 31 typedef UnlinkedPublicNamespace GetImportCallback(String relativeUri);
32 32
33 /** 33 /**
34 * Type of the callback used by the prelinker to obtain unlinked summaries of 34 * Type of the callback used by the prelinker to obtain unlinked summaries of
35 * part files of the library to be prelinked. [relaviteUri] should be 35 * part files of the library to be prelinked. [relativeUri] should be
36 * interpreted relative to the defining compilation unit of the library being 36 * interpreted relative to the defining compilation unit of the library being
37 * prelinked. 37 * prelinked.
38 * 38 *
39 * If no file exists at the given uri, `null` should be returned. 39 * If no file exists at the given uri, `null` should be returned.
40 */ 40 */
41 typedef UnlinkedUnit GetPartCallback(String relativeUri); 41 typedef UnlinkedUnit GetPartCallback(String relativeUri);
42 42
43 /** 43 /**
44 * A [_Meaning] representing a class.
45 */
46 class _ClassMeaning extends _Meaning {
47 final Map<String, _Meaning> namespace;
Paul Berry 2016/01/26 00:47:21 Instead of adding _ClassMeaning as a new class, I
scheglov 2016/01/26 04:34:49 It could work, but in _PrefixMeaning all its _Mean
48
49 _ClassMeaning(int unit, int dependency, int numTypeParameters, this.namespace)
50 : super(unit, ReferenceKind.classOrEnum, dependency, numTypeParameters);
51 }
52
53 /**
44 * A [_Meaning] stores all the information necessary to find the declaration 54 * A [_Meaning] stores all the information necessary to find the declaration
45 * referred to by a name in a namespace. 55 * referred to by a name in a namespace.
46 */ 56 */
47 class _Meaning { 57 class _Meaning {
48 /** 58 /**
49 * Which unit in the dependent library contains the declared entity. 59 * Which unit in the dependent library contains the declared entity.
50 */ 60 */
51 final int unit; 61 final int unit;
52 62
53 /** 63 /**
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 183
174 Map<String, _Meaning> aggregated = <String, _Meaning>{}; 184 Map<String, _Meaning> aggregated = <String, _Meaning>{};
175 185
176 for (int unitNum = 0; unitNum < unitUris.length; unitNum++) { 186 for (int unitNum = 0; unitNum < unitUris.length; unitNum++) {
177 String unitUri = unitUris[unitNum]; 187 String unitUri = unitUris[unitNum];
178 UnlinkedPublicNamespace importedNamespace = getImportCached(unitUri); 188 UnlinkedPublicNamespace importedNamespace = getImportCached(unitUri);
179 if (importedNamespace == null) { 189 if (importedNamespace == null) {
180 continue; 190 continue;
181 } 191 }
182 for (UnlinkedPublicName name in importedNamespace.names) { 192 for (UnlinkedPublicName name in importedNamespace.names) {
183 aggregated.putIfAbsent( 193 aggregated.putIfAbsent(name.name, () {
184 name.name, 194 if (name.kind == ReferenceKind.classOrEnum) {
185 () => new _Meaning( 195 Map<String, _Meaning> namespace = <String, _Meaning>{};
186 unitNum, name.kind, dependency, name.numTypeParameters)); 196 name.executables.forEach((executable) {
197 namespace[executable.name] = new _Meaning(unitNum,
198 executable.kind, dependency, executable.numTypeParameters);
199 });
200 return new _ClassMeaning(
201 unitNum, dependency, name.numTypeParameters, namespace);
202 }
203 return new _Meaning(
204 unitNum, name.kind, dependency, name.numTypeParameters);
205 });
187 } 206 }
188 } 207 }
189 208
190 dependencyToPublicNamespace.add(aggregated); 209 dependencyToPublicNamespace.add(aggregated);
191 return aggregated; 210 return aggregated;
192 } 211 }
193 212
194 /** 213 /**
195 * Compute the export namespace for the library whose URI is reachable from 214 * Compute the export namespace for the library whose URI is reachable from
196 * [definingUnit] via [relativeUri], by aggregating together public namespace 215 * [definingUnit] via [relativeUri], by aggregating together public namespace
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return exportNamespace; 249 return exportNamespace;
231 } 250 }
232 251
233 /** 252 /**
234 * Extract all the names defined in [unit] (which is the [unitNum]th unit in 253 * Extract all the names defined in [unit] (which is the [unitNum]th unit in
235 * the library being prelinked) and store them in [privateNamespace]. 254 * the library being prelinked) and store them in [privateNamespace].
236 * Excludes names introduced by `import` statements. 255 * Excludes names introduced by `import` statements.
237 */ 256 */
238 void extractPrivateNames(UnlinkedUnit unit, int unitNum) { 257 void extractPrivateNames(UnlinkedUnit unit, int unitNum) {
239 for (UnlinkedClass cls in unit.classes) { 258 for (UnlinkedClass cls in unit.classes) {
240 privateNamespace.putIfAbsent( 259 privateNamespace.putIfAbsent(cls.name, () {
241 cls.name, 260 Map<String, _Meaning> namespace = <String, _Meaning>{};
242 () => new _Meaning(unitNum, ReferenceKind.classOrEnum, 0, 261 cls.executables.forEach((executable) {
243 cls.typeParameters.length)); 262 namespace[executable.name] = new _Meaning(
263 unitNum,
264 executable.kind == UnlinkedExecutableKind.constructor
265 ? ReferenceKind.constructor
266 : ReferenceKind.staticMethod,
267 0,
268 executable.typeParameters.length);
269 });
270 return new _ClassMeaning(
271 unitNum, 0, cls.typeParameters.length, namespace);
272 });
244 } 273 }
245 for (UnlinkedEnum enm in unit.enums) { 274 for (UnlinkedEnum enm in unit.enums) {
246 privateNamespace.putIfAbsent(enm.name, 275 privateNamespace.putIfAbsent(enm.name,
247 () => new _Meaning(unitNum, ReferenceKind.classOrEnum, 0, 0)); 276 () => new _Meaning(unitNum, ReferenceKind.classOrEnum, 0, 0));
248 } 277 }
249 for (UnlinkedExecutable executable in unit.executables) { 278 for (UnlinkedExecutable executable in unit.executables) {
250 privateNamespace.putIfAbsent( 279 privateNamespace.putIfAbsent(
251 executable.name, 280 executable.name,
252 () => new _Meaning( 281 () => new _Meaning(
253 unitNum, 282 unitNum,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 LinkedUnitBuilder linkUnit(UnlinkedUnit unit) { 387 LinkedUnitBuilder linkUnit(UnlinkedUnit unit) {
359 if (unit == null) { 388 if (unit == null) {
360 return new LinkedUnitBuilder(); 389 return new LinkedUnitBuilder();
361 } 390 }
362 Map<int, Map<String, _Meaning>> prefixNamespaces = 391 Map<int, Map<String, _Meaning>> prefixNamespaces =
363 <int, Map<String, _Meaning>>{}; 392 <int, Map<String, _Meaning>>{};
364 List<LinkedReferenceBuilder> references = <LinkedReferenceBuilder>[]; 393 List<LinkedReferenceBuilder> references = <LinkedReferenceBuilder>[];
365 for (int i = 0; i < unit.references.length; i++) { 394 for (int i = 0; i < unit.references.length; i++) {
366 UnlinkedReference reference = unit.references[i]; 395 UnlinkedReference reference = unit.references[i];
367 Map<String, _Meaning> namespace; 396 Map<String, _Meaning> namespace;
368 if (reference.prefixReference != 0) { 397 if (reference.prefixReference == 0) {
398 namespace = privateNamespace;
399 } else {
369 // Prefix references must always point backward. 400 // Prefix references must always point backward.
370 assert(reference.prefixReference < i); 401 assert(reference.prefixReference < i);
371 namespace = prefixNamespaces[reference.prefixReference]; 402 namespace = prefixNamespaces[reference.prefixReference];
372 // Prefix references must always point to proper prefixes. 403 // Prefix references must always point to proper prefixes.
373 assert(namespace != null); 404 assert(namespace != null);
374 } else {
375 namespace = privateNamespace;
376 } 405 }
377 _Meaning meaning = namespace[reference.name]; 406 _Meaning meaning = namespace[reference.name];
378 if (meaning != null) { 407 if (meaning != null) {
379 if (meaning is _PrefixMeaning) { 408 if (meaning is _PrefixMeaning) {
380 prefixNamespaces[i] = meaning.namespace; 409 prefixNamespaces[i] = meaning.namespace;
410 } else if (meaning is _ClassMeaning) {
411 prefixNamespaces[i] = meaning.namespace;
381 } 412 }
382 references.add(meaning.encodeReference()); 413 references.add(meaning.encodeReference());
383 } else { 414 } else {
384 references 415 references
385 .add(new LinkedReferenceBuilder(kind: ReferenceKind.unresolved)); 416 .add(new LinkedReferenceBuilder(kind: ReferenceKind.unresolved));
386 } 417 }
387 } 418 }
388 return new LinkedUnitBuilder(references: references); 419 return new LinkedUnitBuilder(references: references);
389 } 420 }
390 421
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 * [sourceUri] is also relative. 476 * [sourceUri] is also relative.
446 */ 477 */
447 String resolveUri(String sourceUri, String relativeUri) { 478 String resolveUri(String sourceUri, String relativeUri) {
448 if (sourceUri == null) { 479 if (sourceUri == null) {
449 return relativeUri; 480 return relativeUri;
450 } else { 481 } else {
451 return Uri.parse(sourceUri).resolve(relativeUri).toString(); 482 return Uri.parse(sourceUri).resolve(relativeUri).toString();
452 } 483 }
453 } 484 }
454 } 485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698