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 | 2 |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 import 'dart:collection' show HashMap, HashSet; | 6 import 'dart:collection' show HashMap, HashSet; |
7 import 'dart:math' show min, max; | 7 import 'dart:math' show min, max; |
8 | 8 |
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; | 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 | 956 |
957 // Emit things that come after the ES6 `class ... { ... }`. | 957 // Emit things that come after the ES6 `class ... { ... }`. |
958 var jsPeerNames = _getJSPeerNames(classElem); | 958 var jsPeerNames = _getJSPeerNames(classElem); |
959 JS.Statement deferredBaseClass = | 959 JS.Statement deferredBaseClass = |
960 _setBaseClass(classElem, className, jsPeerNames, body); | 960 _setBaseClass(classElem, className, jsPeerNames, body); |
961 | 961 |
962 var finishGenericTypeTest = _emitClassTypeTests(classElem, className, body); | 962 var finishGenericTypeTest = _emitClassTypeTests(classElem, className, body); |
963 | 963 |
964 _emitVirtualFieldSymbols(classElem, body); | 964 _emitVirtualFieldSymbols(classElem, body); |
965 _emitClassSignature(methods, allFields, classElem, ctors, className, body); | 965 _emitClassSignature(methods, allFields, classElem, ctors, className, body); |
966 _initExtensionSymbols(classElem, methods, fields); | |
966 _defineExtensionMembers(className, body); | 967 _defineExtensionMembers(className, body); |
967 _emitClassMetadata(node.metadata, className, body); | 968 _emitClassMetadata(node.metadata, className, body); |
968 | 969 |
969 JS.Statement classDef = _statement(body); | 970 JS.Statement classDef = _statement(body); |
970 | 971 |
971 var typeFormals = classElem.typeParameters; | 972 var typeFormals = classElem.typeParameters; |
972 if (typeFormals.isNotEmpty) { | 973 if (typeFormals.isNotEmpty) { |
973 classDef = _defineClassTypeArguments( | 974 classDef = _defineClassTypeArguments( |
974 classElem, typeFormals, classDef, className, deferredBaseClass); | 975 classElem, typeFormals, classDef, className, deferredBaseClass); |
975 } | 976 } |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1975 if (options.emitMetadata && metadata.isNotEmpty) { | 1976 if (options.emitMetadata && metadata.isNotEmpty) { |
1976 body.add(js.statement('#[#.metadata] = () => #;', [ | 1977 body.add(js.statement('#[#.metadata] = () => #;', [ |
1977 className, | 1978 className, |
1978 _runtimeModule, | 1979 _runtimeModule, |
1979 new JS.ArrayInitializer( | 1980 new JS.ArrayInitializer( |
1980 new List<JS.Expression>.from(metadata.map(_instantiateAnnotation))) | 1981 new List<JS.Expression>.from(metadata.map(_instantiateAnnotation))) |
1981 ])); | 1982 ])); |
1982 } | 1983 } |
1983 } | 1984 } |
1984 | 1985 |
1986 /// Ensure `dartx.` symbols we will use are present. | |
1987 void _initExtensionSymbols(ClassElement classElem, | |
1988 List<MethodDeclaration> methods, List<FieldDeclaration> fields) { | |
1989 if (_extensionTypes.hasNativeSubtype(classElem.type)) { | |
1990 for (var m in methods) { | |
1991 if (!m.isAbstract && | |
1992 !m.isStatic && | |
1993 resolutionMap.elementDeclaredByMethodDeclaration(m).isPublic) { | |
1994 _declareMemberName(m.element, useExtension: true); | |
Jennifer Messerly
2017/08/31 21:00:48
FYI, this is mostly the original code, restored fr
| |
1995 } | |
1996 } | |
1997 for (var fieldDecl in fields) { | |
1998 if (!fieldDecl.isStatic) { | |
1999 for (var field in fieldDecl.fields.variables) { | |
2000 var e = field.element as FieldElement; | |
2001 if (e.isPublic) { | |
2002 _declareMemberName(e.getter, useExtension: true); | |
2003 } | |
2004 } | |
2005 } | |
2006 } | |
2007 } | |
2008 } | |
2009 | |
1985 /// If a concrete class implements one of our extensions, we might need to | 2010 /// If a concrete class implements one of our extensions, we might need to |
1986 /// add forwarders. | 2011 /// add forwarders. |
1987 void _defineExtensionMembers( | 2012 void _defineExtensionMembers( |
1988 JS.Expression className, List<JS.Statement> body) { | 2013 JS.Expression className, List<JS.Statement> body) { |
1989 void emitExtensions( | 2014 void emitExtensions( |
1990 JS.Expression target, Iterable<ExecutableElement> extensions) { | 2015 JS.Expression target, Iterable<ExecutableElement> extensions) { |
1991 if (extensions.isEmpty) return; | 2016 if (extensions.isEmpty) return; |
1992 | 2017 |
1993 var names = extensions | 2018 var names = extensions |
1994 .map((e) => _declareMemberName(e, useExtension: false)) | 2019 .map((e) => _declareMemberName(e, useExtension: false)) |
(...skipping 4103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6098 '~/': 'floorDivide', | 6123 '~/': 'floorDivide', |
6099 '*': 'times', | 6124 '*': 'times', |
6100 '%': 'modulo', | 6125 '%': 'modulo', |
6101 '|': 'bitOr', | 6126 '|': 'bitOr', |
6102 '^': 'bitXor', | 6127 '^': 'bitXor', |
6103 '&': 'bitAnd', | 6128 '&': 'bitAnd', |
6104 '<<': 'leftShift', | 6129 '<<': 'leftShift', |
6105 '>>': 'rightShift', | 6130 '>>': 'rightShift', |
6106 '~': 'bitNot' | 6131 '~': 'bitNot' |
6107 }; | 6132 }; |
OLD | NEW |