OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dev_compiler.src.codegen.js_codegen; | 5 library dev_compiler.src.codegen.js_codegen; |
6 | 6 |
7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; | 7 import 'dart:collection' show HashSet, HashMap, SplayTreeSet; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 for (FieldDeclaration member in fields) { | 769 for (FieldDeclaration member in fields) { |
770 for (VariableDeclaration fieldDecl in member.fields.variables) { | 770 for (VariableDeclaration fieldDecl in member.fields.variables) { |
771 var field = fieldDecl.element as FieldElement; | 771 var field = fieldDecl.element as FieldElement; |
772 if (_fieldsNeedingStorage.contains(field)) { | 772 if (_fieldsNeedingStorage.contains(field)) { |
773 body.add(_overrideField(field)); | 773 body.add(_overrideField(field)); |
774 } | 774 } |
775 } | 775 } |
776 } | 776 } |
777 | 777 |
778 // Emit the signature on the class recording the runtime type information | 778 // Emit the signature on the class recording the runtime type information |
| 779 var extensions = _extensionsToImplement(classElem); |
779 { | 780 { |
780 var tStatics = <JS.Property>[]; | 781 var tStatics = <JS.Property>[]; |
781 var tMethods = <JS.Property>[]; | 782 var tMethods = <JS.Property>[]; |
782 var sNames = <JS.Expression>[]; | 783 var sNames = <JS.Expression>[]; |
783 for (MethodDeclaration node in methods) { | 784 for (MethodDeclaration node in methods) { |
784 if (!(node.isSetter || node.isGetter || node.isAbstract)) { | 785 if (!(node.isSetter || node.isGetter || node.isAbstract)) { |
785 var name = node.name.name; | 786 var name = node.name.name; |
786 var element = node.element; | 787 var element = node.element; |
787 var inheritedElement = | 788 var inheritedElement = |
788 classElem.lookUpInheritedConcreteMethod(name, currentLibrary); | 789 classElem.lookUpInheritedConcreteMethod(name, currentLibrary); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 var sigFields = <JS.Property>[]; | 821 var sigFields = <JS.Property>[]; |
821 if (!tCtors.isEmpty) sigFields.add(build('constructors', tCtors)); | 822 if (!tCtors.isEmpty) sigFields.add(build('constructors', tCtors)); |
822 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods)); | 823 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods)); |
823 if (!tStatics.isEmpty) { | 824 if (!tStatics.isEmpty) { |
824 assert(!sNames.isEmpty); | 825 assert(!sNames.isEmpty); |
825 var aNames = new JS.Property( | 826 var aNames = new JS.Property( |
826 _propertyName('names'), new JS.ArrayInitializer(sNames)); | 827 _propertyName('names'), new JS.ArrayInitializer(sNames)); |
827 sigFields.add(build('statics', tStatics)); | 828 sigFields.add(build('statics', tStatics)); |
828 sigFields.add(aNames); | 829 sigFields.add(aNames); |
829 } | 830 } |
830 if (!sigFields.isEmpty) { | 831 if (!sigFields.isEmpty || extensions.isNotEmpty) { |
831 var sig = new JS.ObjectInitializer(sigFields); | 832 var sig = new JS.ObjectInitializer(sigFields); |
832 var classExpr = new JS.Identifier(name); | 833 var classExpr = new JS.Identifier(name); |
833 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig])); | 834 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig])); |
834 } | 835 } |
835 } | 836 } |
836 | 837 |
837 // If a concrete class implements one of our extensions, we might need to | 838 // If a concrete class implements one of our extensions, we might need to |
838 // add forwarders. | 839 // add forwarders. |
839 var extensions = _extensionsToImplement(classElem); | |
840 if (extensions.isNotEmpty) { | 840 if (extensions.isNotEmpty) { |
841 var methodNames = <JS.Expression>[]; | 841 var methodNames = <JS.Expression>[]; |
842 for (var e in extensions) { | 842 for (var e in extensions) { |
843 methodNames.add(_elementMemberName(e)); | 843 methodNames.add(_elementMemberName(e)); |
844 } | 844 } |
845 body.add(js.statement('dart.defineExtensionMembers(#, #);', [ | 845 body.add(js.statement('dart.defineExtensionMembers(#, #);', [ |
846 name, | 846 name, |
847 new JS.ArrayInitializer(methodNames, multiline: methodNames.length > 4) | 847 new JS.ArrayInitializer(methodNames, multiline: methodNames.length > 4) |
848 ])); | 848 ])); |
849 } | 849 } |
(...skipping 2531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3381 t = fillDynamicTypeArgs(t, rules.provider) as InterfaceType; | 3381 t = fillDynamicTypeArgs(t, rules.provider) as InterfaceType; |
3382 t.interfaces.forEach(_addExtensionType); | 3382 t.interfaces.forEach(_addExtensionType); |
3383 t.mixins.forEach(_addExtensionType); | 3383 t.mixins.forEach(_addExtensionType); |
3384 _addExtensionType(t.superclass); | 3384 _addExtensionType(t.superclass); |
3385 } | 3385 } |
3386 | 3386 |
3387 String generateLibrary(LibraryUnit unit) { | 3387 String generateLibrary(LibraryUnit unit) { |
3388 // Clone the AST first, so we can mutate it. | 3388 // Clone the AST first, so we can mutate it. |
3389 unit = unit.clone(); | 3389 unit = unit.clone(); |
3390 var library = unit.library.element.library; | 3390 var library = unit.library.element.library; |
3391 var fields = findFieldsNeedingStorage(unit); | 3391 var fields = findFieldsNeedingStorage(unit, _extensionTypes); |
3392 var codegen = | 3392 var codegen = |
3393 new JSCodegenVisitor(compiler, rules, library, _extensionTypes, fields); | 3393 new JSCodegenVisitor(compiler, rules, library, _extensionTypes, fields); |
3394 var module = codegen.emitLibrary(unit); | 3394 var module = codegen.emitLibrary(unit); |
3395 var out = compiler.getOutputPath(library.source.uri); | 3395 var out = compiler.getOutputPath(library.source.uri); |
3396 return writeJsLibrary(module, out, | 3396 return writeJsLibrary(module, out, |
3397 emitSourceMaps: options.emitSourceMaps, | 3397 emitSourceMaps: options.emitSourceMaps, |
3398 arrowFnBindThisWorkaround: options.arrowFnBindThisWorkaround); | 3398 arrowFnBindThisWorkaround: options.arrowFnBindThisWorkaround); |
3399 } | 3399 } |
3400 } | 3400 } |
3401 | 3401 |
(...skipping 15 matching lines...) Expand all Loading... |
3417 | 3417 |
3418 /// A special kind of element created by the compiler, signifying a temporary | 3418 /// A special kind of element created by the compiler, signifying a temporary |
3419 /// variable. These objects use instance equality, and should be shared | 3419 /// variable. These objects use instance equality, and should be shared |
3420 /// everywhere in the tree where they are treated as the same variable. | 3420 /// everywhere in the tree where they are treated as the same variable. |
3421 class TemporaryVariableElement extends LocalVariableElementImpl { | 3421 class TemporaryVariableElement extends LocalVariableElementImpl { |
3422 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); | 3422 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); |
3423 | 3423 |
3424 int get hashCode => identityHashCode(this); | 3424 int get hashCode => identityHashCode(this); |
3425 bool operator ==(Object other) => identical(this, other); | 3425 bool operator ==(Object other) => identical(this, other); |
3426 } | 3426 } |
OLD | NEW |