| 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.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 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 final List<KernelProcedureBuilder> nativeMethods = <KernelProcedureBuilder>[]; | 62 final List<KernelProcedureBuilder> nativeMethods = <KernelProcedureBuilder>[]; |
| 63 | 63 |
| 64 final List<KernelTypeVariableBuilder> boundlessTypeVariables = | 64 final List<KernelTypeVariableBuilder> boundlessTypeVariables = |
| 65 <KernelTypeVariableBuilder>[]; | 65 <KernelTypeVariableBuilder>[]; |
| 66 | 66 |
| 67 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader) | 67 KernelLibraryBuilder(Uri uri, Uri fileUri, Loader loader) |
| 68 : library = new Library(uri, fileUri: relativizeUri(fileUri)), | 68 : library = new Library(uri, fileUri: relativizeUri(fileUri)), |
| 69 super(loader, fileUri); | 69 super(loader, fileUri); |
| 70 | 70 |
| 71 Library get target => library; |
| 72 |
| 71 Uri get uri => library.importUri; | 73 Uri get uri => library.importUri; |
| 72 | 74 |
| 73 KernelTypeBuilder addNamedType( | 75 KernelTypeBuilder addNamedType( |
| 74 String name, List<KernelTypeBuilder> arguments, int charOffset) { | 76 String name, List<KernelTypeBuilder> arguments, int charOffset) { |
| 75 KernelNamedTypeBuilder type = | 77 KernelNamedTypeBuilder type = |
| 76 new KernelNamedTypeBuilder(name, arguments, charOffset, fileUri); | 78 new KernelNamedTypeBuilder(name, arguments, charOffset, fileUri); |
| 77 if (identical(name, "dynamic")) { | 79 if (identical(name, "dynamic")) { |
| 78 type.builder = | 80 type.builder = |
| 79 new DynamicTypeBuilder(const DynamicType(), this, charOffset); | 81 new DynamicTypeBuilder(const DynamicType(), this, charOffset); |
| 80 } else { | 82 } else { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 var builder = new KernelTypeVariableBuilder(name, this, charOffset, bound); | 275 var builder = new KernelTypeVariableBuilder(name, this, charOffset, bound); |
| 274 boundlessTypeVariables.add(builder); | 276 boundlessTypeVariables.add(builder); |
| 275 return builder; | 277 return builder; |
| 276 } | 278 } |
| 277 | 279 |
| 278 void buildBuilder(Builder builder) { | 280 void buildBuilder(Builder builder) { |
| 279 if (builder is SourceClassBuilder) { | 281 if (builder is SourceClassBuilder) { |
| 280 Class cls = builder.build(this); | 282 Class cls = builder.build(this); |
| 281 library.addClass(cls); | 283 library.addClass(cls); |
| 282 } else if (builder is KernelFieldBuilder) { | 284 } else if (builder is KernelFieldBuilder) { |
| 283 library.addMember(builder.build(library)..isStatic = true); | 285 library.addMember(builder.build(this)..isStatic = true); |
| 284 } else if (builder is KernelProcedureBuilder) { | 286 } else if (builder is KernelProcedureBuilder) { |
| 285 library.addMember(builder.build(library)..isStatic = true); | 287 library.addMember(builder.build(this)..isStatic = true); |
| 286 } else if (builder is FunctionTypeAliasBuilder) { | 288 } else if (builder is FunctionTypeAliasBuilder) { |
| 287 // Kernel discard typedefs and use their corresponding function types | 289 // Kernel discard typedefs and use their corresponding function types |
| 288 // directly. | 290 // directly. |
| 289 } else if (builder is KernelEnumBuilder) { | 291 } else if (builder is KernelEnumBuilder) { |
| 290 library.addClass(builder.build(this)); | 292 library.addClass(builder.build(this)); |
| 291 } else if (builder is PrefixBuilder) { | 293 } else if (builder is PrefixBuilder) { |
| 292 // Ignored. Kernel doesn't represent prefixes. | 294 // Ignored. Kernel doesn't represent prefixes. |
| 293 } else { | 295 } else { |
| 294 internalError("Unhandled builder: ${builder.runtimeType}"); | 296 internalError("Unhandled builder: ${builder.runtimeType}"); |
| 295 } | 297 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 i = 0; | 389 i = 0; |
| 388 for (KernelTypeVariableBuilder variable in original) { | 390 for (KernelTypeVariableBuilder variable in original) { |
| 389 copy[i++].bound = variable.bound?.subst(substitution); | 391 copy[i++].bound = variable.bound?.subst(substitution); |
| 390 } | 392 } |
| 391 return copy; | 393 return copy; |
| 392 } | 394 } |
| 393 | 395 |
| 394 int finishTypeVariables(ClassBuilder object) { | 396 int finishTypeVariables(ClassBuilder object) { |
| 395 int count = boundlessTypeVariables.length; | 397 int count = boundlessTypeVariables.length; |
| 396 for (KernelTypeVariableBuilder builder in boundlessTypeVariables) { | 398 for (KernelTypeVariableBuilder builder in boundlessTypeVariables) { |
| 397 builder.finish(object); | 399 builder.finish(this, object); |
| 398 } | 400 } |
| 399 boundlessTypeVariables.clear(); | 401 boundlessTypeVariables.clear(); |
| 400 return count; | 402 return count; |
| 401 } | 403 } |
| 402 | 404 |
| 403 @override | 405 @override |
| 404 void includePart(covariant KernelLibraryBuilder part) { | 406 void includePart(covariant KernelLibraryBuilder part) { |
| 405 super.includePart(part); | 407 super.includePart(part); |
| 406 nativeMethods.addAll(part.nativeMethods); | 408 nativeMethods.addAll(part.nativeMethods); |
| 407 boundlessTypeVariables.addAll(part.boundlessTypeVariables); | 409 boundlessTypeVariables.addAll(part.boundlessTypeVariables); |
| 408 assert(mixinApplicationClasses.isEmpty); | 410 assert(mixinApplicationClasses.isEmpty); |
| 409 } | 411 } |
| 410 } | 412 } |
| 411 | 413 |
| 412 bool isConstructorName(String name, String className) { | 414 bool isConstructorName(String name, String className) { |
| 413 if (name.startsWith(className)) { | 415 if (name.startsWith(className)) { |
| 414 if (name.length == className.length) return true; | 416 if (name.length == className.length) return true; |
| 415 if (name.startsWith(".", className.length)) return true; | 417 if (name.startsWith(".", className.length)) return true; |
| 416 } | 418 } |
| 417 return false; | 419 return false; |
| 418 } | 420 } |
| OLD | NEW |