| 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:kernel/ast.dart' show AsyncMarker, ProcedureKind; | 7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; |
| 8 | 8 |
| 9 import '../combinator.dart' show Combinator; | 9 import '../combinator.dart' show Combinator; |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 final Map<String, Builder> exports = <String, Builder>{}; | 54 final Map<String, Builder> exports = <String, Builder>{}; |
| 55 | 55 |
| 56 final Scope scope = new Scope(<String, Builder>{}, null, isModifiable: false); | 56 final Scope scope = new Scope(<String, Builder>{}, null, isModifiable: false); |
| 57 | 57 |
| 58 final Uri fileUri; | 58 final Uri fileUri; |
| 59 | 59 |
| 60 final List<List> implementationBuilders = <List<List>>[]; | 60 final List<List> implementationBuilders = <List<List>>[]; |
| 61 | 61 |
| 62 String name; | 62 String name; |
| 63 | 63 |
| 64 String partOf; | 64 String partOfName; |
| 65 |
| 66 Uri partOfUri; |
| 65 | 67 |
| 66 List<MetadataBuilder> metadata; | 68 List<MetadataBuilder> metadata; |
| 67 | 69 |
| 68 /// The current declaration that is being built. When we start parsing a | 70 /// The current declaration that is being built. When we start parsing a |
| 69 /// declaration (class, method, and so on), we don't have enough information | 71 /// declaration (class, method, and so on), we don't have enough information |
| 70 /// to create a builder and this object records its members and types until, | 72 /// to create a builder and this object records its members and types until, |
| 71 /// for example, [addClass] is called. | 73 /// for example, [addClass] is called. |
| 72 DeclarationBuilder<T> currentDeclaration; | 74 DeclarationBuilder<T> currentDeclaration; |
| 73 | 75 |
| 74 SourceLibraryBuilder(this.loader, Uri fileUri) | 76 SourceLibraryBuilder(this.loader, Uri fileUri) |
| 75 : fileUri = fileUri, | 77 : fileUri = fileUri, |
| 76 super(fileUri) { | 78 super(fileUri) { |
| 77 currentDeclaration = libraryDeclaration; | 79 currentDeclaration = libraryDeclaration; |
| 78 } | 80 } |
| 79 | 81 |
| 80 Uri get uri; | 82 Uri get uri; |
| 81 | 83 |
| 82 bool get isPart => partOf != null; | 84 bool get isPart => partOfName != null || partOfUri != null; |
| 83 | 85 |
| 84 Map<String, Builder> get members => libraryDeclaration.members; | 86 Map<String, Builder> get members => libraryDeclaration.members; |
| 85 | 87 |
| 86 List<T> get types => libraryDeclaration.types; | 88 List<T> get types => libraryDeclaration.types; |
| 87 | 89 |
| 88 /// When parsing a class, this returns a map of its members (that have been | 90 /// When parsing a class, this returns a map of its members (that have been |
| 89 /// parsed so far). | 91 /// parsed so far). |
| 90 Map<String, MemberBuilder> get classMembers { | 92 Map<String, MemberBuilder> get classMembers { |
| 91 assert(currentDeclaration.parent == libraryDeclaration); | 93 assert(currentDeclaration.parent == libraryDeclaration); |
| 92 return currentDeclaration.members; | 94 return currentDeclaration.members; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (uri.scheme == "dart") { | 150 if (uri.scheme == "dart") { |
| 149 resolvedUri = new Uri(scheme: "dart", path: "${uri.path}/$path"); | 151 resolvedUri = new Uri(scheme: "dart", path: "${uri.path}/$path"); |
| 150 newFileUri = fileUri.resolve(path); | 152 newFileUri = fileUri.resolve(path); |
| 151 } else { | 153 } else { |
| 152 resolvedUri = uri.resolve(path); | 154 resolvedUri = uri.resolve(path); |
| 153 newFileUri = fileUri.resolve(path); | 155 newFileUri = fileUri.resolve(path); |
| 154 } | 156 } |
| 155 parts.add(loader.read(resolvedUri, newFileUri)); | 157 parts.add(loader.read(resolvedUri, newFileUri)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void addPartOf(List<MetadataBuilder> metadata, String name) { | 160 void addPartOf(List<MetadataBuilder> metadata, String name, String uri) { |
| 159 partOf = name; | 161 partOfName = name; |
| 162 partOfUri = uri == null ? null : this.uri.resolve(uri); |
| 160 } | 163 } |
| 161 | 164 |
| 162 void addClass( | 165 void addClass( |
| 163 List<MetadataBuilder> metadata, | 166 List<MetadataBuilder> metadata, |
| 164 int modifiers, | 167 int modifiers, |
| 165 String name, | 168 String name, |
| 166 List<TypeVariableBuilder> typeVariables, | 169 List<TypeVariableBuilder> typeVariables, |
| 167 T supertype, | 170 T supertype, |
| 168 List<T> interfaces, | 171 List<T> interfaces, |
| 169 int charOffset); | 172 int charOffset); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 if (part == this) { | 340 if (part == this) { |
| 338 addCompileTimeError(-1, "A file can't be a part of itself."); | 341 addCompileTimeError(-1, "A file can't be a part of itself."); |
| 339 } else { | 342 } else { |
| 340 includePart(part); | 343 includePart(part); |
| 341 } | 344 } |
| 342 } | 345 } |
| 343 } | 346 } |
| 344 | 347 |
| 345 void includePart(SourceLibraryBuilder<T, R> part) { | 348 void includePart(SourceLibraryBuilder<T, R> part) { |
| 346 if (name != null) { | 349 if (name != null) { |
| 347 if (part.partOf == null) { | 350 if (!part.isPart) { |
| 348 warning( | 351 warning( |
| 349 part.fileUri, | 352 part.fileUri, |
| 350 -1, | 353 -1, |
| 351 "Has no 'part of' declaration but is used as " | 354 "Has no 'part of' declaration but is used as " |
| 352 "a part by ${name} ($uri)."); | 355 "a part by ${name} ($uri)."); |
| 353 parts.remove(part); | 356 parts.remove(part); |
| 354 return; | 357 return; |
| 355 } | 358 } |
| 356 if (part.partOf != name) { | 359 if (part.partOfName != name && part.partOfUri != uri) { |
| 357 warning( | 360 String partName = part.partOfName ?? "${part.partOfUri}"; |
| 358 part.fileUri, | 361 String myName = name == null ? "'$uri'" : "'${name}' ($uri)"; |
| 359 -1, | 362 warning(part.fileUri, -1, |
| 360 "Is part of '${part.partOf}' but is used as " | 363 "Is part of '$partName' but is used as a part by $myName."); |
| 361 "a part by '${name}' ($uri)."); | |
| 362 parts.remove(part); | 364 parts.remove(part); |
| 363 return; | 365 return; |
| 364 } | 366 } |
| 365 } | 367 } |
| 366 part.members.forEach((String name, Builder builder) { | 368 part.members.forEach((String name, Builder builder) { |
| 367 if (builder.next != null) { | 369 if (builder.next != null) { |
| 368 assert(builder.next.next == null); | 370 assert(builder.next.next == null); |
| 369 addBuilder(name, builder.next, builder.next.charOffset); | 371 addBuilder(name, builder.next, builder.next.charOffset); |
| 370 } | 372 } |
| 371 addBuilder(name, builder, builder.charOffset); | 373 addBuilder(name, builder, builder.charOffset); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 } | 520 } |
| 519 | 521 |
| 520 /// Called to register [procedure] as a factory whose types are collected in | 522 /// Called to register [procedure] as a factory whose types are collected in |
| 521 /// [factoryDeclaration]. Later, once the class has been built, we can | 523 /// [factoryDeclaration]. Later, once the class has been built, we can |
| 522 /// synthesize type variables on the factory matching the class'. | 524 /// synthesize type variables on the factory matching the class'. |
| 523 void addFactoryDeclaration( | 525 void addFactoryDeclaration( |
| 524 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 526 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 525 factoryDeclarations[procedure] = factoryDeclaration; | 527 factoryDeclarations[procedure] = factoryDeclaration; |
| 526 } | 528 } |
| 527 } | 529 } |
| OLD | NEW |