| 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_loader; | 5 library fasta.source_loader; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:typed_data' show Uint8List; | 9 import 'dart:typed_data' show Uint8List; |
| 10 | 10 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // will have the same length. | 332 // will have the same length. |
| 333 Iterable<ClassBuilder> input = const []; | 333 Iterable<ClassBuilder> input = const []; |
| 334 Iterable<ClassBuilder> output = classes; | 334 Iterable<ClassBuilder> output = classes; |
| 335 while (input.length != output.length) { | 335 while (input.length != output.length) { |
| 336 input = output; | 336 input = output; |
| 337 output = directSupertypes(input); | 337 output = directSupertypes(input); |
| 338 } | 338 } |
| 339 return output; | 339 return output; |
| 340 } | 340 } |
| 341 | 341 |
| 342 /// Whether [library] is allowed to define classes that extend or implement | |
| 343 /// restricted types, such as `bool`, `int`, `double`, `num`, and `String`. By | |
| 344 /// default this is only allowed within the implementation of `dart:core`, but | |
| 345 /// some target implementations may need to override this to allow doing this | |
| 346 /// in other internal platform libraries. | |
| 347 bool canImplementRestrictedTypes(LibraryBuilder library) => | |
| 348 library == coreLibrary; | |
| 349 | |
| 350 void checkSemantics() { | 342 void checkSemantics() { |
| 351 List<ClassBuilder> allClasses = target.collectAllClasses(); | 343 List<ClassBuilder> allClasses = target.collectAllClasses(); |
| 352 Iterable<ClassBuilder> candidates = cyclicCandidates(allClasses); | 344 Iterable<ClassBuilder> candidates = cyclicCandidates(allClasses); |
| 353 Map<ClassBuilder, Set<ClassBuilder>> realCycles = | 345 Map<ClassBuilder, Set<ClassBuilder>> realCycles = |
| 354 <ClassBuilder, Set<ClassBuilder>>{}; | 346 <ClassBuilder, Set<ClassBuilder>>{}; |
| 355 for (ClassBuilder cls in candidates) { | 347 for (ClassBuilder cls in candidates) { |
| 356 Set<ClassBuilder> cycles = cyclicCandidates(allSupertypes(cls)); | 348 Set<ClassBuilder> cycles = cyclicCandidates(allSupertypes(cls)); |
| 357 if (cycles.isNotEmpty) { | 349 if (cycles.isNotEmpty) { |
| 358 realCycles[cls] = cycles; | 350 realCycles[cls] = cycles; |
| 359 } | 351 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 388 for (ClassBuilder cls in allClasses) { | 380 for (ClassBuilder cls in allClasses) { |
| 389 if (cls.library.loader != this) continue; | 381 if (cls.library.loader != this) continue; |
| 390 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); | 382 Set<ClassBuilder> directSupertypes = new Set<ClassBuilder>(); |
| 391 target.addDirectSupertype(cls, directSupertypes); | 383 target.addDirectSupertype(cls, directSupertypes); |
| 392 for (ClassBuilder supertype in directSupertypes) { | 384 for (ClassBuilder supertype in directSupertypes) { |
| 393 if (supertype is EnumBuilder) { | 385 if (supertype is EnumBuilder) { |
| 394 cls.addCompileTimeError( | 386 cls.addCompileTimeError( |
| 395 cls.charOffset, | 387 cls.charOffset, |
| 396 "'${supertype.name}' is an enum and can't be extended or " | 388 "'${supertype.name}' is an enum and can't be extended or " |
| 397 "implemented."); | 389 "implemented."); |
| 398 } else if (!canImplementRestrictedTypes(cls.library) && | 390 } else if (!cls.library.mayImplementRestrictedTypes && |
| 399 blackListedClasses.contains(supertype)) { | 391 blackListedClasses.contains(supertype)) { |
| 400 cls.addCompileTimeError( | 392 cls.addCompileTimeError( |
| 401 cls.charOffset, | 393 cls.charOffset, |
| 402 "'${supertype.name}' is restricted and can't be extended or " | 394 "'${supertype.name}' is restricted and can't be extended or " |
| 403 "implemented."); | 395 "implemented."); |
| 404 } | 396 } |
| 405 } | 397 } |
| 406 TypeBuilder mixedInType = cls.mixedInType; | 398 TypeBuilder mixedInType = cls.mixedInType; |
| 407 if (mixedInType != null) { | 399 if (mixedInType != null) { |
| 408 bool isClassBuilder = false; | 400 bool isClassBuilder = false; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 512 |
| 521 Expression throwCompileConstantError(Expression error) { | 513 Expression throwCompileConstantError(Expression error) { |
| 522 return target.backendTarget.throwCompileConstantError(coreTypes, error); | 514 return target.backendTarget.throwCompileConstantError(coreTypes, error); |
| 523 } | 515 } |
| 524 | 516 |
| 525 Expression buildCompileTimeError(String message, int offset) { | 517 Expression buildCompileTimeError(String message, int offset) { |
| 526 return target.backendTarget | 518 return target.backendTarget |
| 527 .buildCompileTimeError(coreTypes, message, offset); | 519 .buildCompileTimeError(coreTypes, message, offset); |
| 528 } | 520 } |
| 529 } | 521 } |
| OLD | NEW |