| 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 |
| 11 import '../../base/resolve_relative_uri.dart' show resolveRelativeUri; | 11 import '../../base/resolve_relative_uri.dart' show resolveRelativeUri; |
| 12 | 12 |
| 13 import '../combinator.dart' show Combinator; | 13 import '../combinator.dart' show Combinator; |
| 14 | 14 |
| 15 import '../errors.dart' show inputError, internalError; | 15 import '../deprecated_problems.dart' |
| 16 show deprecated_inputError, deprecated_internalProblem; |
| 16 | 17 |
| 17 import '../export.dart' show Export; | 18 import '../export.dart' show Export; |
| 18 | 19 |
| 19 import '../import.dart' show Import; | 20 import '../import.dart' show Import; |
| 20 | 21 |
| 21 import 'source_loader.dart' show SourceLoader; | 22 import 'source_loader.dart' show SourceLoader; |
| 22 | 23 |
| 23 import '../builder/builder.dart' | 24 import '../builder/builder.dart' |
| 24 show | 25 show |
| 25 Builder, | 26 Builder, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // implementation of MemberBuilder.isTopLevel to test explicitly for a | 276 // implementation of MemberBuilder.isTopLevel to test explicitly for a |
| 276 // LibraryBuilder. | 277 // LibraryBuilder. |
| 277 if (currentDeclaration == libraryDeclaration) { | 278 if (currentDeclaration == libraryDeclaration) { |
| 278 if (builder is MemberBuilder) { | 279 if (builder is MemberBuilder) { |
| 279 builder.parent = this; | 280 builder.parent = this; |
| 280 } else if (builder is TypeDeclarationBuilder) { | 281 } else if (builder is TypeDeclarationBuilder) { |
| 281 builder.parent = this; | 282 builder.parent = this; |
| 282 } else if (builder is PrefixBuilder) { | 283 } else if (builder is PrefixBuilder) { |
| 283 assert(builder.parent == this); | 284 assert(builder.parent == this); |
| 284 } else { | 285 } else { |
| 285 return internalError("Unhandled: ${builder.runtimeType}"); | 286 return deprecated_internalProblem("Unhandled: ${builder.runtimeType}"); |
| 286 } | 287 } |
| 287 } else { | 288 } else { |
| 288 assert(currentDeclaration.parent == libraryDeclaration); | 289 assert(currentDeclaration.parent == libraryDeclaration); |
| 289 } | 290 } |
| 290 bool isConstructor = builder is ProcedureBuilder && | 291 bool isConstructor = builder is ProcedureBuilder && |
| 291 (builder.isConstructor || builder.isFactory); | 292 (builder.isConstructor || builder.isFactory); |
| 292 Map<String, Builder> members = isConstructor | 293 Map<String, Builder> members = isConstructor |
| 293 ? currentDeclaration.constructors | 294 ? currentDeclaration.constructors |
| 294 : (builder.isSetter | 295 : (builder.isSetter |
| 295 ? currentDeclaration.setters | 296 ? currentDeclaration.setters |
| 296 : currentDeclaration.members); | 297 : currentDeclaration.members); |
| 297 Builder existing = members[name]; | 298 Builder existing = members[name]; |
| 298 builder.next = existing; | 299 builder.next = existing; |
| 299 if (builder is PrefixBuilder && existing is PrefixBuilder) { | 300 if (builder is PrefixBuilder && existing is PrefixBuilder) { |
| 300 assert(existing.next == null); | 301 assert(existing.next == null); |
| 301 Builder deferred; | 302 Builder deferred; |
| 302 Builder other; | 303 Builder other; |
| 303 if (builder.deferred) { | 304 if (builder.deferred) { |
| 304 deferred = builder; | 305 deferred = builder; |
| 305 other = existing; | 306 other = existing; |
| 306 } else if (existing.deferred) { | 307 } else if (existing.deferred) { |
| 307 deferred = existing; | 308 deferred = existing; |
| 308 other = builder; | 309 other = builder; |
| 309 } | 310 } |
| 310 if (deferred != null) { | 311 if (deferred != null) { |
| 311 addCompileTimeError( | 312 deprecated_addCompileTimeError( |
| 312 deferred.charOffset, | 313 deferred.charOffset, |
| 313 "Can't use the name '$name' for a deferred library, " | 314 "Can't use the name '$name' for a deferred library, " |
| 314 "as the name is used elsewhere."); | 315 "as the name is used elsewhere."); |
| 315 addCompileTimeError(other.charOffset, "'$name' is used here."); | 316 deprecated_addCompileTimeError( |
| 317 other.charOffset, "'$name' is used here."); |
| 316 } | 318 } |
| 317 return existing | 319 return existing |
| 318 ..exports.merge(builder.exports, | 320 ..exports.merge(builder.exports, |
| 319 (String name, Builder existing, Builder member) { | 321 (String name, Builder existing, Builder member) { |
| 320 return buildAmbiguousBuilder(name, existing, member, charOffset); | 322 return buildAmbiguousBuilder(name, existing, member, charOffset); |
| 321 }); | 323 }); |
| 322 } else if (isDuplicatedDefinition(existing, builder)) { | 324 } else if (isDuplicatedDefinition(existing, builder)) { |
| 323 addCompileTimeError(charOffset, "Duplicated definition of '$name'."); | 325 deprecated_addCompileTimeError( |
| 326 charOffset, "Duplicated definition of '$name'."); |
| 324 } | 327 } |
| 325 return members[name] = builder; | 328 return members[name] = builder; |
| 326 } | 329 } |
| 327 | 330 |
| 328 bool isDuplicatedDefinition(Builder existing, Builder other) { | 331 bool isDuplicatedDefinition(Builder existing, Builder other) { |
| 329 if (existing == null) return false; | 332 if (existing == null) return false; |
| 330 Builder next = existing.next; | 333 Builder next = existing.next; |
| 331 if (next == null) { | 334 if (next == null) { |
| 332 if (existing.isGetter && other.isSetter) return false; | 335 if (existing.isGetter && other.isSetter) return false; |
| 333 if (existing.isSetter && other.isGetter) return false; | 336 if (existing.isSetter && other.isGetter) return false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 361 int charOffset = list[2]; | 364 int charOffset = list[2]; |
| 362 addBuilder(name, builder, charOffset); | 365 addBuilder(name, builder, charOffset); |
| 363 buildBuilder(builder, coreLibrary); | 366 buildBuilder(builder, coreLibrary); |
| 364 } | 367 } |
| 365 canAddImplementationBuilders = false; | 368 canAddImplementationBuilders = false; |
| 366 | 369 |
| 367 scope.setters.forEach((String name, Builder setter) { | 370 scope.setters.forEach((String name, Builder setter) { |
| 368 Builder member = scopeBuilder[name]; | 371 Builder member = scopeBuilder[name]; |
| 369 if (member == null || !member.isField || member.isFinal) return; | 372 if (member == null || !member.isField || member.isFinal) return; |
| 370 // TODO(ahe): charOffset is missing. | 373 // TODO(ahe): charOffset is missing. |
| 371 addCompileTimeError( | 374 deprecated_addCompileTimeError( |
| 372 setter.charOffset, "Conflicts with member '${name}'."); | 375 setter.charOffset, "Conflicts with member '${name}'."); |
| 373 addCompileTimeError( | 376 deprecated_addCompileTimeError( |
| 374 member.charOffset, "Conflicts with setter '${name}'."); | 377 member.charOffset, "Conflicts with setter '${name}'."); |
| 375 }); | 378 }); |
| 376 | 379 |
| 377 return null; | 380 return null; |
| 378 } | 381 } |
| 379 | 382 |
| 380 /// Used to add implementation builder during the call to [build] above. | 383 /// Used to add implementation builder during the call to [build] above. |
| 381 /// Currently, only anonymous mixins are using implementation builders (see | 384 /// Currently, only anonymous mixins are using implementation builders (see |
| 382 /// [KernelMixinApplicationBuilder] | 385 /// [KernelMixinApplicationBuilder] |
| 383 /// (../kernel/kernel_mixin_application_builder.dart)). | 386 /// (../kernel/kernel_mixin_application_builder.dart)). |
| 384 void addImplementationBuilder(String name, Builder builder, int charOffset) { | 387 void addImplementationBuilder(String name, Builder builder, int charOffset) { |
| 385 assert(canAddImplementationBuilders, "$uri"); | 388 assert(canAddImplementationBuilders, "$uri"); |
| 386 implementationBuilders.add([name, builder, charOffset]); | 389 implementationBuilders.add([name, builder, charOffset]); |
| 387 } | 390 } |
| 388 | 391 |
| 389 void validatePart() { | 392 void validatePart() { |
| 390 if (parts.isNotEmpty) { | 393 if (parts.isNotEmpty) { |
| 391 inputError(fileUri, -1, | 394 deprecated_inputError(fileUri, -1, |
| 392 "A file that's a part of a library can't have parts itself."); | 395 "A file that's a part of a library can't have parts itself."); |
| 393 } | 396 } |
| 394 if (exporters.isNotEmpty) { | 397 if (exporters.isNotEmpty) { |
| 395 Export export = exporters.first; | 398 Export export = exporters.first; |
| 396 inputError( | 399 deprecated_inputError( |
| 397 export.fileUri, export.charOffset, "A part can't be exported."); | 400 export.fileUri, export.charOffset, "A part can't be exported."); |
| 398 } | 401 } |
| 399 } | 402 } |
| 400 | 403 |
| 401 void includeParts() { | 404 void includeParts() { |
| 402 Set<Uri> seenParts = new Set<Uri>(); | 405 Set<Uri> seenParts = new Set<Uri>(); |
| 403 for (SourceLibraryBuilder<T, R> part in parts.toList()) { | 406 for (SourceLibraryBuilder<T, R> part in parts.toList()) { |
| 404 if (part == this) { | 407 if (part == this) { |
| 405 addCompileTimeError(-1, "A file can't be a part of itself."); | 408 deprecated_addCompileTimeError(-1, "A file can't be a part of itself."); |
| 406 } else if (seenParts.add(part.fileUri)) { | 409 } else if (seenParts.add(part.fileUri)) { |
| 407 includePart(part); | 410 includePart(part); |
| 408 } else { | 411 } else { |
| 409 addCompileTimeError( | 412 deprecated_addCompileTimeError( |
| 410 -1, "Can't use '${part.fileUri}' as a part more than once."); | 413 -1, "Can't use '${part.fileUri}' as a part more than once."); |
| 411 } | 414 } |
| 412 } | 415 } |
| 413 } | 416 } |
| 414 | 417 |
| 415 void includePart(SourceLibraryBuilder<T, R> part) { | 418 void includePart(SourceLibraryBuilder<T, R> part) { |
| 416 if (part.partOfUri != null) { | 419 if (part.partOfUri != null) { |
| 417 if (uri.resolve(part.partOfUri) != uri) { | 420 if (uri.resolve(part.partOfUri) != uri) { |
| 418 // This is a warning, but the part is still included. | 421 // This is a warning, but the part is still included. |
| 419 addWarning( | 422 deprecated_addWarning( |
| 420 -1, | 423 -1, |
| 421 "Using '${part.relativeFileUri}' as part of '$uri' but its " | 424 "Using '${part.relativeFileUri}' as part of '$uri' but its " |
| 422 "'part of' declaration says '${part.partOfUri}'."); | 425 "'part of' declaration says '${part.partOfUri}'."); |
| 423 if (uri.scheme == "dart" && relativeFileUri.endsWith(part.partOfUri)) { | 426 if (uri.scheme == "dart" && relativeFileUri.endsWith(part.partOfUri)) { |
| 424 addWarning(-1, "See https://github.com/dart-lang/sdk/issues/30072."); | 427 deprecated_addWarning( |
| 428 -1, "See https://github.com/dart-lang/sdk/issues/30072."); |
| 425 } | 429 } |
| 426 } | 430 } |
| 427 } else if (part.partOfName != null) { | 431 } else if (part.partOfName != null) { |
| 428 if (name != null) { | 432 if (name != null) { |
| 429 if (part.partOfName != name) { | 433 if (part.partOfName != name) { |
| 430 // This is a warning, but the part is still included. | 434 // This is a warning, but the part is still included. |
| 431 addWarning( | 435 deprecated_addWarning( |
| 432 -1, | 436 -1, |
| 433 "Using '${part.relativeFileUri}' as part of '$name' but its " | 437 "Using '${part.relativeFileUri}' as part of '$name' but its " |
| 434 "'part of' declaration says '${part.partOfName}'."); | 438 "'part of' declaration says '${part.partOfName}'."); |
| 435 } | 439 } |
| 436 } else { | 440 } else { |
| 437 // This is a warning, but the part is still included. | 441 // This is a warning, but the part is still included. |
| 438 addWarning( | 442 deprecated_addWarning( |
| 439 -1, | 443 -1, |
| 440 "Using '${part.relativeFileUri}' as part of '${relativeFileUri}' " | 444 "Using '${part.relativeFileUri}' as part of '${relativeFileUri}' " |
| 441 "but its 'part of' declaration says '${part.partOfName}'.\n" | 445 "but its 'part of' declaration says '${part.partOfName}'.\n" |
| 442 "Try changing the 'part of' declaration to use a relative " | 446 "Try changing the 'part of' declaration to use a relative " |
| 443 "file name."); | 447 "file name."); |
| 444 } | 448 } |
| 445 } else if (name != null) { | 449 } else if (name != null) { |
| 446 // This is an error, and the part isn't included. | 450 // This is an error, and the part isn't included. |
| 447 assert(!part.isPart); | 451 assert(!part.isPart); |
| 448 addCompileTimeError( | 452 deprecated_addCompileTimeError( |
| 449 -1, | 453 -1, |
| 450 "Can't use ${part.fileUri} as a part, because it has no 'part of'" | 454 "Can't use ${part.fileUri} as a part, because it has no 'part of'" |
| 451 " declaration."); | 455 " declaration."); |
| 452 parts.remove(part); | 456 parts.remove(part); |
| 453 return; | 457 return; |
| 454 } | 458 } |
| 455 part.forEach((String name, Builder builder) { | 459 part.forEach((String name, Builder builder) { |
| 456 if (builder.next != null) { | 460 if (builder.next != null) { |
| 457 assert(builder.next.next == null); | 461 assert(builder.next.next == null); |
| 458 addBuilder(name, builder.next, builder.next.charOffset); | 462 addBuilder(name, builder.next, builder.next.charOffset); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 /// synthesize type variables on the factory matching the class'. | 632 /// synthesize type variables on the factory matching the class'. |
| 629 void addFactoryDeclaration( | 633 void addFactoryDeclaration( |
| 630 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 634 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 631 factoryDeclarations[procedure] = factoryDeclaration; | 635 factoryDeclarations[procedure] = factoryDeclaration; |
| 632 } | 636 } |
| 633 | 637 |
| 634 Scope toScope(Scope parent) { | 638 Scope toScope(Scope parent) { |
| 635 return new Scope(members, setters, parent, isModifiable: false); | 639 return new Scope(members, setters, parent, isModifiable: false); |
| 636 } | 640 } |
| 637 } | 641 } |
| OLD | NEW |