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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/kernel_library_builder.dart

Issue 2780543002: Handle complicated imports. (Closed)
Patch Set: Fix infinite loop. Created 3 years, 8 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 library fasta.kernel_library_builder; 5 library fasta.kernel_library_builder;
6 6
7 import 'package:kernel/ast.dart'; 7 import 'package:kernel/ast.dart';
8 8
9 import 'package:kernel/clone.dart' show CloneVisitor; 9 import 'package:kernel/clone.dart' show CloneVisitor;
10 10
11 import '../errors.dart' show internalError; 11 import '../errors.dart' show internalError;
12 12
13 import '../loader.dart' show Loader; 13 import '../loader.dart' show Loader;
14 14
15 import '../modifier.dart' show abstractMask, staticMask; 15 import '../modifier.dart' show abstractMask, staticMask;
16 16
17 import '../source/source_library_builder.dart' 17 import '../source/source_library_builder.dart'
18 show DeclarationBuilder, SourceLibraryBuilder; 18 show DeclarationBuilder, SourceLibraryBuilder;
19 19
20 import '../source/source_class_builder.dart' show SourceClassBuilder; 20 import '../source/source_class_builder.dart' show SourceClassBuilder;
21 21
22 import '../util/relativize.dart' show relativizeUri; 22 import '../util/relativize.dart' show relativizeUri;
23 23
24 import 'kernel_builder.dart' 24 import 'kernel_builder.dart'
25 show 25 show
26 AccessErrorBuilder,
26 Builder, 27 Builder,
27 BuiltinTypeBuilder, 28 BuiltinTypeBuilder,
28 ClassBuilder, 29 ClassBuilder,
29 ConstructorReferenceBuilder, 30 ConstructorReferenceBuilder,
30 FormalParameterBuilder, 31 FormalParameterBuilder,
31 FunctionTypeAliasBuilder, 32 FunctionTypeAliasBuilder,
33 InvalidTypeBuilder,
32 KernelConstructorBuilder, 34 KernelConstructorBuilder,
33 KernelEnumBuilder, 35 KernelEnumBuilder,
34 KernelFieldBuilder, 36 KernelFieldBuilder,
35 KernelFormalParameterBuilder, 37 KernelFormalParameterBuilder,
36 KernelFunctionTypeAliasBuilder, 38 KernelFunctionTypeAliasBuilder,
37 KernelFunctionTypeBuilder, 39 KernelFunctionTypeBuilder,
38 KernelInvalidTypeBuilder, 40 KernelInvalidTypeBuilder,
39 KernelMixinApplicationBuilder, 41 KernelMixinApplicationBuilder,
40 KernelNamedMixinApplicationBuilder, 42 KernelNamedMixinApplicationBuilder,
41 KernelNamedTypeBuilder, 43 KernelNamedTypeBuilder,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 internalError("Unhandled builder: ${builder.runtimeType}"); 320 internalError("Unhandled builder: ${builder.runtimeType}");
319 } 321 }
320 } 322 }
321 323
322 Library build() { 324 Library build() {
323 super.build(); 325 super.build();
324 library.name = name; 326 library.name = name;
325 return library; 327 return library;
326 } 328 }
327 329
330 @override
328 Builder buildAmbiguousBuilder( 331 Builder buildAmbiguousBuilder(
329 String name, Builder builder, Builder other, int charOffset) { 332 String name, Builder builder, Builder other, int charOffset,
333 {bool isExport: false, bool isImport: false}) {
334 if (builder == other) return builder;
335 if (builder is InvalidTypeBuilder) return builder;
336 if (other is InvalidTypeBuilder) return other;
337 if (builder is AccessErrorBuilder) {
338 AccessErrorBuilder error = builder;
339 builder = error.builder;
340 }
341 if (other is AccessErrorBuilder) {
342 AccessErrorBuilder error = other;
343 other = error.builder;
344 }
345 bool isLocal = false;
346 Builder preferred;
347 Uri uri;
348 Uri otherUri;
349 Uri preferredUri;
350 Uri hiddenUri;
351 if (members[name] == builder) {
352 isLocal = true;
353 preferred = builder;
354 hiddenUri = other.computeLibraryUri();
355 } else {
356 uri = builder.computeLibraryUri();
357 otherUri = other.computeLibraryUri();
358 if (otherUri?.scheme == "dart" && uri?.scheme != "dart") {
359 preferred = builder;
360 preferredUri = uri;
361 hiddenUri = otherUri;
362 } else if (uri?.scheme == "dart" && otherUri?.scheme != "dart") {
363 preferred = other;
364 preferredUri = otherUri;
365 hiddenUri = uri;
366 }
367 }
368 if (preferred != null) {
369 if (isLocal) {
370 if (isExport) {
371 addNit(charOffset,
372 "Local definition of '$name' hides export from '${hiddenUri}'.");
373 } else {
374 addNit(charOffset,
375 "Local definition of '$name' hides import from '${hiddenUri}'.");
376 }
377 } else {
378 if (isExport) {
379 addNit(
380 charOffset,
381 "Export of '$name' (from '${preferredUri}') hides export from "
382 "'${hiddenUri}'.");
383 } else {
384 addNit(
385 charOffset,
386 "Import of '$name' (from '${preferredUri}') hides import from "
387 "'${hiddenUri}'.");
388 }
389 }
390 return preferred;
391 }
330 if (builder.next == null && other.next == null) { 392 if (builder.next == null && other.next == null) {
331 if (builder.isGetter && other.isSetter) { 393 if (builder.isGetter && other.isSetter) {
332 return new MixedAccessor(builder, other, this); 394 return new MixedAccessor(builder, other, this);
333 } else if (builder.isSetter && other.isGetter) { 395 } else if (builder.isSetter && other.isGetter) {
334 return new MixedAccessor(other, builder, this); 396 return new MixedAccessor(other, builder, this);
335 } 397 }
398 if (isImport && builder is PrefixBuilder && other is PrefixBuilder) {
399 // Handles the case where the same prefix is used for different
400 // imports.
401 PrefixBuilder prefix = builder;
402 other.exports.forEach((String name, Builder member) {
403 Builder existing = exports[name];
404 if (existing != null) {
405 if (existing != member) {
406 member = buildAmbiguousBuilder(name, existing, member, charOffset,
407 isExport: isExport, isImport: isImport);
408 }
409 }
410 prefix.exports[name] = member;
411 });
412 return builder;
413 }
414 }
415 if (isExport) {
416 addNit(charOffset,
417 "'$name' is exported from both '${uri}' and '${otherUri}'.");
418 } else {
419 addNit(charOffset,
420 "'$name' is imported from both '${uri}' and '${otherUri}'.");
336 } 421 }
337 return new KernelInvalidTypeBuilder(name, charOffset, fileUri); 422 return new KernelInvalidTypeBuilder(name, charOffset, fileUri);
338 } 423 }
339 424
340 int finishStaticInvocations() { 425 int finishStaticInvocations() {
341 CloneVisitor cloner; 426 CloneVisitor cloner;
342 for (var list in argumentsWithMissingDefaultValues) { 427 for (var list in argumentsWithMissingDefaultValues) {
343 final Arguments arguments = list[0]; 428 final Arguments arguments = list[0];
344 final FunctionNode function = list[1]; 429 final FunctionNode function = list[1];
345 430
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 512 }
428 } 513 }
429 514
430 bool isConstructorName(String name, String className) { 515 bool isConstructorName(String name, String className) {
431 if (name.startsWith(className)) { 516 if (name.startsWith(className)) {
432 if (name.length == className.length) return true; 517 if (name.length == className.length) return true;
433 if (name.startsWith(".", className.length)) return true; 518 if (name.startsWith(".", className.length)) return true;
434 } 519 }
435 return false; 520 return false;
436 } 521 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/import.dart ('k') | pkg/front_end/lib/src/fasta/source/source_library_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698