Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.source_library_builder; | 5 library fasta.source_library_builder; |
| 6 | 6 |
| 7 import 'package:front_end/src/scanner/token.dart' show Token; | 7 import 'package:front_end/src/scanner/token.dart' show Token; |
| 8 | 8 |
| 9 import 'package:kernel/ast.dart' show ProcedureKind; | 9 import 'package:kernel/ast.dart' show ProcedureKind; |
| 10 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 final List<List> implementationBuilders = <List<List>>[]; | 59 final List<List> implementationBuilders = <List<List>>[]; |
| 60 | 60 |
| 61 /// Indicates whether type inference (and type promotion) should be disabled | 61 /// Indicates whether type inference (and type promotion) should be disabled |
| 62 /// for this library. | 62 /// for this library. |
| 63 final bool disableTypeInference; | 63 final bool disableTypeInference; |
| 64 | 64 |
| 65 String name; | 65 String name; |
| 66 | 66 |
| 67 String partOfName; | 67 String partOfName; |
| 68 | 68 |
| 69 Uri partOfUri; | 69 String partOfUri; |
| 70 | 70 |
| 71 List<MetadataBuilder> metadata; | 71 List<MetadataBuilder> metadata; |
| 72 | 72 |
| 73 /// The current declaration that is being built. When we start parsing a | 73 /// The current declaration that is being built. When we start parsing a |
| 74 /// declaration (class, method, and so on), we don't have enough information | 74 /// declaration (class, method, and so on), we don't have enough information |
| 75 /// to create a builder and this object records its members and types until, | 75 /// to create a builder and this object records its members and types until, |
| 76 /// for example, [addClass] is called. | 76 /// for example, [addClass] is called. |
| 77 DeclarationBuilder<T> currentDeclaration; | 77 DeclarationBuilder<T> currentDeclaration; |
| 78 | 78 |
| 79 bool canAddImplementationBuilders = false; | 79 bool canAddImplementationBuilders = false; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 if (uri.scheme != "package") { | 170 if (uri.scheme != "package") { |
| 171 newFileUri = fileUri.resolve(path); | 171 newFileUri = fileUri.resolve(path); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 parts.add(loader.read(resolvedUri, charOffset, | 174 parts.add(loader.read(resolvedUri, charOffset, |
| 175 fileUri: newFileUri, accessor: this)); | 175 fileUri: newFileUri, accessor: this)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void addPartOf(List<MetadataBuilder> metadata, String name, String uri) { | 178 void addPartOf(List<MetadataBuilder> metadata, String name, String uri) { |
| 179 partOfName = name; | 179 partOfName = name; |
| 180 partOfUri = uri == null ? null : this.uri.resolve(uri); | 180 partOfUri = uri; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void addClass( | 183 void addClass( |
| 184 List<MetadataBuilder> metadata, | 184 List<MetadataBuilder> metadata, |
| 185 int modifiers, | 185 int modifiers, |
| 186 String name, | 186 String name, |
| 187 List<TypeVariableBuilder> typeVariables, | 187 List<TypeVariableBuilder> typeVariables, |
| 188 T supertype, | 188 T supertype, |
| 189 List<T> interfaces, | 189 List<T> interfaces, |
| 190 int charOffset); | 190 int charOffset); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 } else if (seenParts.add(part.fileUri)) { | 406 } else if (seenParts.add(part.fileUri)) { |
| 407 includePart(part); | 407 includePart(part); |
| 408 } else { | 408 } else { |
| 409 addCompileTimeError( | 409 addCompileTimeError( |
| 410 -1, "Can't use '${part.fileUri}' as a part more than once."); | 410 -1, "Can't use '${part.fileUri}' as a part more than once."); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 void includePart(SourceLibraryBuilder<T, R> part) { | 415 void includePart(SourceLibraryBuilder<T, R> part) { |
| 416 if (name != null) { | 416 if (part.partOfUri != null) { |
| 417 if (!part.isPart) { | 417 if (uri.resolve(part.partOfUri) != uri) { |
| 418 addCompileTimeError( | 418 // This is a warning, but the part is still included. |
| 419 -1, | |
| 420 "Can't use ${part.fileUri} as a part, because it has no 'part of'" | |
| 421 " declaration."); | |
| 422 parts.remove(part); | |
| 423 return; | |
| 424 } | |
| 425 if (part.partOfName != name && part.partOfUri != uri) { | |
| 426 String partName = part.partOfName ?? "${part.partOfUri}"; | |
| 427 String myName = name == null ? "'$uri'" : "'${name}' ($uri)"; | |
| 428 addWarning( | 419 addWarning( |
| 429 -1, | 420 -1, |
| 430 "Using '${part.fileUri}' as part of '$myName' but its 'part of'" | 421 "Using '${part.relativeFileUri}' as part of '$uri' but its " |
| 431 " declaration says '$partName'."); | 422 "'part of' declaration says '${part.partOfUri}'."); |
| 432 // The part is still included. | 423 if (uri.scheme == "dart" && relativeFileUri.endsWith(part.partOfUri)) { |
| 424 addWarning(-1, "See https://github.com/dart-lang/sdk/issues/30072."); | |
| 425 } | |
| 433 } | 426 } |
| 427 } else if (part.partOfName != null) { | |
| 428 if (name != null) { | |
| 429 // This is a warning, but the part is still included. | |
| 430 addWarning( | |
|
Johnni Winther
2017/07/05 12:44:24
This warning should only be emitted if `part.partO
ahe
2017/07/05 13:01:02
Done.
| |
| 431 -1, | |
| 432 "Using '${part.relativeFileUri}' as part of '$name' but its " | |
| 433 "'part of' declaration says '${part.partOfName}'."); | |
| 434 } else { | |
| 435 // This is a warning, but the part is still included. | |
| 436 addWarning( | |
| 437 -1, | |
| 438 "Using '${part.relativeFileUri}' as part of '${relativeFileUri}' " | |
| 439 "but its 'part of' declaration says '${part.partOfName}'.\n" | |
| 440 "Try changing the 'part of' declaration to use a relative " | |
| 441 "file name."); | |
| 442 } | |
| 443 } else if (name != null) { | |
| 444 // This is an error, and the part isn't included. | |
| 445 assert(!part.isPart); | |
| 446 addCompileTimeError( | |
| 447 -1, | |
| 448 "Can't use ${part.fileUri} as a part, because it has no 'part of'" | |
| 449 " declaration."); | |
| 450 parts.remove(part); | |
| 451 return; | |
| 434 } | 452 } |
| 435 part.forEach((String name, Builder builder) { | 453 part.forEach((String name, Builder builder) { |
| 436 if (builder.next != null) { | 454 if (builder.next != null) { |
| 437 assert(builder.next.next == null); | 455 assert(builder.next.next == null); |
| 438 addBuilder(name, builder.next, builder.next.charOffset); | 456 addBuilder(name, builder.next, builder.next.charOffset); |
| 439 } | 457 } |
| 440 addBuilder(name, builder, builder.charOffset); | 458 addBuilder(name, builder, builder.charOffset); |
| 441 }); | 459 }); |
| 442 types.addAll(part.types); | 460 types.addAll(part.types); |
| 443 constructorReferences.addAll(part.constructorReferences); | 461 constructorReferences.addAll(part.constructorReferences); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 /// synthesize type variables on the factory matching the class'. | 626 /// synthesize type variables on the factory matching the class'. |
| 609 void addFactoryDeclaration( | 627 void addFactoryDeclaration( |
| 610 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 628 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 611 factoryDeclarations[procedure] = factoryDeclaration; | 629 factoryDeclarations[procedure] = factoryDeclaration; |
| 612 } | 630 } |
| 613 | 631 |
| 614 Scope toScope(Scope parent) { | 632 Scope toScope(Scope parent) { |
| 615 return new Scope(members, setters, parent, isModifiable: false); | 633 return new Scope(members, setters, parent, isModifiable: false); |
| 616 } | 634 } |
| 617 } | 635 } |
| OLD | NEW |