| 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection' show Queue; | 6 import 'dart:collection' show Queue; |
| 7 | 7 |
| 8 import 'package:kernel/ast.dart' as ir; | 8 import 'package:kernel/ast.dart' as ir; |
| 9 import 'package:kernel/verifier.dart' show CheckParentPointers; | 9 import 'package:kernel/verifier.dart' show CheckParentPointers; |
| 10 | 10 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Future<ir.Library> loadLibrary(Uri uri) async { | 145 Future<ir.Library> loadLibrary(Uri uri) async { |
| 146 return libraryToIr(await compiler.libraryLoader.loadLibrary(uri)); | 146 return libraryToIr(await compiler.libraryLoader.loadLibrary(uri)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 ir.Library libraryToIr(LibraryElement library) { | 149 ir.Library libraryToIr(LibraryElement library) { |
| 150 library = library.declaration; | 150 library = library.declaration; |
| 151 return libraries.putIfAbsent(library, () { | 151 return libraries.putIfAbsent(library, () { |
| 152 String name = library.hasLibraryName ? library.libraryName : null; | 152 String name = library.hasLibraryName ? library.libraryName : null; |
| 153 ir.Library libraryNode = new ir.Library(library.canonicalUri, | 153 ir.Library libraryNode = new ir.Library(library.canonicalUri, |
| 154 name: name, classes: null, procedures: null, fields: null); | 154 name: name, classes: null, procedures: null, fields: null); |
| 155 new ir.CanonicalName.dummy().bindTo(libraryNode); |
| 155 addWork(library, () { | 156 addWork(library, () { |
| 156 Queue<ir.Class> classes = new Queue<ir.Class>(); | 157 Queue<ir.Class> classes = new Queue<ir.Class>(); |
| 157 Queue<ir.Member> members = new Queue<ir.Member>(); | 158 Queue<ir.Member> members = new Queue<ir.Member>(); |
| 158 library.implementation.forEachLocalMember((Element e) { | 159 library.implementation.forEachLocalMember((Element e) { |
| 159 if (e.isClass) { | 160 if (e.isClass) { |
| 160 ClassElement cls = e; | 161 ClassElement cls = e; |
| 161 if (!cls.isResolved) return; | 162 if (!cls.isResolved) return; |
| 162 classes.addFirst(classToIr(cls)); | 163 classes.addFirst(classToIr(cls)); |
| 163 } else if (e.isFunction || e.isAccessor) { | 164 } else if (e.isFunction || e.isAccessor) { |
| 164 if (!compiler.resolution.hasBeenResolved(e) && !e.isMalformed) { | 165 if (!compiler.resolution.hasBeenResolved(e) && !e.isMalformed) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 assert(cls.isResolved); | 205 assert(cls.isResolved); |
| 205 String name = computeName(cls); | 206 String name = computeName(cls); |
| 206 ir.Class classNode = new ir.Class( | 207 ir.Class classNode = new ir.Class( |
| 207 name: name, | 208 name: name, |
| 208 isAbstract: cls.isAbstract, | 209 isAbstract: cls.isAbstract, |
| 209 typeParameters: null, | 210 typeParameters: null, |
| 210 implementedTypes: null, | 211 implementedTypes: null, |
| 211 constructors: null, | 212 constructors: null, |
| 212 procedures: null, | 213 procedures: null, |
| 213 fields: null); | 214 fields: null); |
| 215 new ir.CanonicalName.dummy().bindTo(classNode); |
| 214 addWork(cls, () { | 216 addWork(cls, () { |
| 215 if (cls.supertype != null) { | 217 if (cls.supertype != null) { |
| 216 classNode.supertype = supertypeToIr(cls.supertype); | 218 classNode.supertype = supertypeToIr(cls.supertype); |
| 217 } | 219 } |
| 218 if (cls.isMixinApplication) { | 220 if (cls.isMixinApplication) { |
| 219 MixinApplicationElement mixinApplication = cls; | 221 MixinApplicationElement mixinApplication = cls; |
| 220 classNode.mixedInType = supertypeToIr(mixinApplication.mixinType); | 222 classNode.mixedInType = supertypeToIr(mixinApplication.mixinType); |
| 221 } | 223 } |
| 222 classNode.parent = libraryToIr(cls.library); | 224 classNode.parent = libraryToIr(cls.library); |
| 223 if (cls.isUnnamedMixinApplication) { | 225 if (cls.isUnnamedMixinApplication) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 ir.Constructor constructor; | 434 ir.Constructor constructor; |
| 433 ir.Procedure procedure; | 435 ir.Procedure procedure; |
| 434 ir.Name name = irName(function.name, function); | 436 ir.Name name = irName(function.name, function); |
| 435 bool isNative = isNativeMethod(function); | 437 bool isNative = isNativeMethod(function); |
| 436 if (function.isGenerativeConstructor) { | 438 if (function.isGenerativeConstructor) { |
| 437 member = constructor = new ir.Constructor(null, | 439 member = constructor = new ir.Constructor(null, |
| 438 name: name, | 440 name: name, |
| 439 isConst: function.isConst, | 441 isConst: function.isConst, |
| 440 isExternal: isNative || function.isExternal, | 442 isExternal: isNative || function.isExternal, |
| 441 initializers: null); | 443 initializers: null); |
| 444 new ir.CanonicalName.dummy().bindTo(constructor); |
| 442 } else { | 445 } else { |
| 443 member = procedure = new ir.Procedure(name, null, null, | 446 member = procedure = new ir.Procedure(name, null, null, |
| 444 isAbstract: function.isAbstract, | 447 isAbstract: function.isAbstract, |
| 445 isStatic: function.isStatic || | 448 isStatic: function.isStatic || |
| 446 function.isTopLevel || | 449 function.isTopLevel || |
| 447 function.isFactoryConstructor, | 450 function.isFactoryConstructor, |
| 448 isExternal: isNative || function.isExternal, | 451 isExternal: isNative || function.isExternal, |
| 449 isConst: false); // TODO(ahe): When is this true? | 452 isConst: false); // TODO(ahe): When is this true? |
| 453 new ir.CanonicalName.dummy().bindTo(procedure); |
| 450 } | 454 } |
| 451 addWork(function, () { | 455 addWork(function, () { |
| 452 setParent(member, function); | 456 setParent(member, function); |
| 453 KernelVisitor visitor = | 457 KernelVisitor visitor = |
| 454 new KernelVisitor(function, function.treeElements, this); | 458 new KernelVisitor(function, function.treeElements, this); |
| 455 beginFactoryScope(function); | 459 beginFactoryScope(function); |
| 456 IrFunction irFunction = visitor.buildFunction(); | 460 IrFunction irFunction = visitor.buildFunction(); |
| 457 // TODO(ahe): Add addFunction/set function to [ir.Procedure]. | 461 // TODO(ahe): Add addFunction/set function to [ir.Procedure]. |
| 458 irFunction.node.parent = member; | 462 irFunction.node.parent = member; |
| 459 if (irFunction.isConstructor) { | 463 if (irFunction.isConstructor) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 538 |
| 535 field = field.implementation; | 539 field = field.implementation; |
| 536 ir.DartType type = | 540 ir.DartType type = |
| 537 field.isMalformed ? const ir.InvalidType() : typeToIr(field.type); | 541 field.isMalformed ? const ir.InvalidType() : typeToIr(field.type); |
| 538 ir.Field fieldNode = new ir.Field(irName(field.memberName.text, field), | 542 ir.Field fieldNode = new ir.Field(irName(field.memberName.text, field), |
| 539 type: type, | 543 type: type, |
| 540 initializer: null, | 544 initializer: null, |
| 541 isFinal: field.isFinal, | 545 isFinal: field.isFinal, |
| 542 isStatic: field.isStatic || field.isTopLevel, | 546 isStatic: field.isStatic || field.isTopLevel, |
| 543 isConst: field.isConst); | 547 isConst: field.isConst); |
| 548 new ir.CanonicalName.dummy().bindTo(fieldNode); |
| 544 addWork(field, () { | 549 addWork(field, () { |
| 545 setParent(fieldNode, field); | 550 setParent(fieldNode, field); |
| 546 if (!field.isMalformed) { | 551 if (!field.isMalformed) { |
| 547 if (field.initializer != null) { | 552 if (field.initializer != null) { |
| 548 KernelVisitor visitor = | 553 KernelVisitor visitor = |
| 549 new KernelVisitor(field, field.treeElements, this); | 554 new KernelVisitor(field, field.treeElements, this); |
| 550 fieldNode.initializer = visitor.buildInitializer() | 555 fieldNode.initializer = visitor.buildInitializer() |
| 551 ..parent = fieldNode; | 556 ..parent = fieldNode; |
| 552 } else if (!field.isInstanceMember) { | 557 } else if (!field.isInstanceMember) { |
| 553 fieldNode.initializer = new ir.NullLiteral()..parent = fieldNode; | 558 fieldNode.initializer = new ir.NullLiteral()..parent = fieldNode; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 789 } |
| 785 | 790 |
| 786 class ConstructorTarget { | 791 class ConstructorTarget { |
| 787 final ConstructorElement element; | 792 final ConstructorElement element; |
| 788 final ResolutionDartType type; | 793 final ResolutionDartType type; |
| 789 | 794 |
| 790 ConstructorTarget(this.element, this.type); | 795 ConstructorTarget(this.element, this.type); |
| 791 | 796 |
| 792 String toString() => "ConstructorTarget($element, $type)"; | 797 String toString() => "ConstructorTarget($element, $type)"; |
| 793 } | 798 } |
| OLD | NEW |