Chromium Code Reviews| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 | 181 |
| 182 /// The main entry point to JavaScript code generation. | 182 /// The main entry point to JavaScript code generation. |
| 183 /// | 183 /// |
| 184 /// Takes the metadata for the build unit, as well as resolved trees and | 184 /// Takes the metadata for the build unit, as well as resolved trees and |
| 185 /// errors, and computes the output module code and optionally the source map. | 185 /// errors, and computes the output module code and optionally the source map. |
| 186 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, | 186 JSModuleFile compile(BuildUnit unit, List<CompilationUnit> compilationUnits, |
| 187 List<String> errors) { | 187 List<String> errors) { |
| 188 _buildUnit = unit; | 188 _buildUnit = unit; |
| 189 _libraryRoot = _buildUnit.libraryRoot; | 189 _libraryRoot = _buildUnit.libraryRoot; |
| 190 if (!_libraryRoot.endsWith(separator)) { | 190 if (!_libraryRoot.endsWith(separator)) { |
| 191 _libraryRoot = '$_libraryRoot${separator}'; | 191 _libraryRoot += separator; |
| 192 } | 192 } |
| 193 | 193 |
| 194 var module = _emitModule(compilationUnits); | 194 var module = _emitModule(compilationUnits); |
| 195 var dartApiSummary = _summarizeModule(compilationUnits); | 195 var dartApiSummary = _summarizeModule(compilationUnits); |
| 196 | 196 |
| 197 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); | 197 return new JSModuleFile(unit.name, errors, options, module, dartApiSummary); |
| 198 } | 198 } |
| 199 | 199 |
| 200 List<int> _summarizeModule(List<CompilationUnit> units) { | 200 List<int> _summarizeModule(List<CompilationUnit> units) { |
| 201 if (!options.summarizeApi) return null; | 201 if (!options.summarizeApi) return null; |
| (...skipping 1597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1799 for (MethodDeclaration node in methods) { | 1799 for (MethodDeclaration node in methods) { |
| 1800 var name = node.name.name; | 1800 var name = node.name.name; |
| 1801 var element = resolutionMap.elementDeclaredByMethodDeclaration(node); | 1801 var element = resolutionMap.elementDeclaredByMethodDeclaration(node); |
| 1802 // TODO(vsm): Clean up all the nasty duplication. | 1802 // TODO(vsm): Clean up all the nasty duplication. |
| 1803 if (node.isAbstract) { | 1803 if (node.isAbstract) { |
| 1804 continue; | 1804 continue; |
| 1805 } | 1805 } |
| 1806 | 1806 |
| 1807 Function lookup; | 1807 Function lookup; |
| 1808 List<JS.Property> tMember; | 1808 List<JS.Property> tMember; |
| 1809 JS.Expression type; | |
| 1810 if (node.isGetter) { | 1809 if (node.isGetter) { |
| 1811 lookup = classElem.lookUpInheritedConcreteGetter; | 1810 lookup = classElem.lookUpInheritedConcreteGetter; |
| 1812 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; | 1811 tMember = node.isStatic ? tStaticGetters : tInstanceGetters; |
| 1813 } else if (node.isSetter) { | 1812 } else if (node.isSetter) { |
| 1814 lookup = classElem.lookUpInheritedConcreteSetter; | 1813 lookup = classElem.lookUpInheritedConcreteSetter; |
| 1815 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; | 1814 tMember = node.isStatic ? tStaticSetters : tInstanceSetters; |
| 1816 } else { | 1815 } else { |
| 1817 // Method | 1816 // Method |
| 1818 lookup = classElem.lookUpInheritedConcreteMethod; | 1817 lookup = classElem.lookUpInheritedConcreteMethod; |
| 1819 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; | 1818 tMember = node.isStatic ? tStaticMethods : tInstanceMethods; |
| 1820 } | 1819 } |
| 1821 | 1820 |
| 1822 type = _emitAnnotatedFunctionType(element.type, node.metadata, | 1821 // Swap in "Object" over parameter types that are covariant overrides. |
| 1822 var objectType = context.typeProvider.objectType; | |
| 1823 var reifiedType = element is MethodElement | |
| 1824 ? element.getReifiedType(objectType) | |
| 1825 : element.type; | |
| 1826 var type = _emitAnnotatedFunctionType(reifiedType, node.metadata, | |
| 1823 parameters: node.parameters?.parameters, | 1827 parameters: node.parameters?.parameters, |
| 1824 nameType: options.hoistSignatureTypes, | 1828 nameType: options.hoistSignatureTypes, |
| 1825 hoistType: options.hoistSignatureTypes, | 1829 hoistType: options.hoistSignatureTypes, |
| 1826 definite: true); | 1830 definite: true); |
| 1827 | 1831 |
| 1832 // Don't add redundant signatures for inherited unchanged methods. | |
| 1828 var inheritedElement = lookup(name, currentLibrary); | 1833 var inheritedElement = lookup(name, currentLibrary); |
| 1829 if (inheritedElement != null && inheritedElement.type == element.type) { | 1834 if (inheritedElement != null && |
| 1835 (inheritedElement is! MethodElement || | |
|
Leaf
2017/01/18 01:51:45
Is this right? You're not checking that the type
Bob Nystrom
2017/01/18 21:42:52
Oops, fixed. Sorry.
| |
| 1836 inheritedElement.getReifiedType(objectType) == reifiedType)) { | |
| 1830 continue; | 1837 continue; |
| 1831 } | 1838 } |
| 1839 | |
| 1832 var memberName = _declareMemberName(element); | 1840 var memberName = _declareMemberName(element); |
| 1833 var property = new JS.Property(memberName, type); | 1841 var property = new JS.Property(memberName, type); |
| 1834 tMember.add(property); | 1842 tMember.add(property); |
| 1835 // TODO(vsm): Why do we need this? | 1843 // TODO(vsm): Why do we need this? |
| 1836 if (node.isStatic && !node.isGetter && !node.isSetter) { | 1844 if (node.isStatic && !node.isGetter && !node.isSetter) { |
| 1837 sNames.add(memberName); | 1845 sNames.add(memberName); |
| 1838 } | 1846 } |
| 1839 } | 1847 } |
| 1840 | 1848 |
| 1841 var tInstanceFields = <JS.Property>[]; | 1849 var tInstanceFields = <JS.Property>[]; |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2901 {List<FormalParameter> parameters, | 2909 {List<FormalParameter> parameters, |
| 2902 bool lowerTypedef: false, | 2910 bool lowerTypedef: false, |
| 2903 bool nameType: true, | 2911 bool nameType: true, |
| 2904 bool hoistType: true, | 2912 bool hoistType: true, |
| 2905 definite: false}) { | 2913 definite: false}) { |
| 2906 var parts = _emitFunctionTypeParts(type, | 2914 var parts = _emitFunctionTypeParts(type, |
| 2907 parameters: parameters, | 2915 parameters: parameters, |
| 2908 lowerTypedef: lowerTypedef, | 2916 lowerTypedef: lowerTypedef, |
| 2909 nameType: nameType, | 2917 nameType: nameType, |
| 2910 hoistType: hoistType); | 2918 hoistType: hoistType); |
| 2911 var helper = (definite) ? 'definiteFunctionType' : 'functionType'; | 2919 var helper = definite ? 'definiteFunctionType' : 'functionType'; |
| 2912 var fullType = _callHelper('${helper}(#)', [parts]); | 2920 var fullType = _callHelper('${helper}(#)', [parts]); |
| 2913 if (!nameType) return fullType; | 2921 if (!nameType) return fullType; |
| 2914 return _typeTable.nameType(type, fullType, | 2922 return _typeTable.nameType(type, fullType, |
| 2915 hoistType: hoistType, definite: definite); | 2923 hoistType: hoistType, definite: definite); |
| 2916 } | 2924 } |
| 2917 | 2925 |
| 2918 JS.Expression _emitAnnotatedFunctionType( | 2926 JS.Expression _emitAnnotatedFunctionType( |
| 2919 FunctionType type, List<Annotation> metadata, | 2927 FunctionType type, List<Annotation> metadata, |
| 2920 {List<FormalParameter> parameters, | 2928 {List<FormalParameter> parameters, |
| 2921 bool lowerTypedef: false, | 2929 bool lowerTypedef: false, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2936 List<JS.Expression> _emitFunctionTypeParts(FunctionType type, | 2944 List<JS.Expression> _emitFunctionTypeParts(FunctionType type, |
| 2937 {List<FormalParameter> parameters, | 2945 {List<FormalParameter> parameters, |
| 2938 bool lowerTypedef: false, | 2946 bool lowerTypedef: false, |
| 2939 bool nameType: true, | 2947 bool nameType: true, |
| 2940 bool hoistType: true}) { | 2948 bool hoistType: true}) { |
| 2941 var parameterTypes = type.normalParameterTypes; | 2949 var parameterTypes = type.normalParameterTypes; |
| 2942 var optionalTypes = type.optionalParameterTypes; | 2950 var optionalTypes = type.optionalParameterTypes; |
| 2943 var namedTypes = type.namedParameterTypes; | 2951 var namedTypes = type.namedParameterTypes; |
| 2944 var rt = | 2952 var rt = |
| 2945 _emitType(type.returnType, nameType: nameType, hoistType: hoistType); | 2953 _emitType(type.returnType, nameType: nameType, hoistType: hoistType); |
| 2954 | |
| 2946 var ra = _emitTypeNames(parameterTypes, parameters, | 2955 var ra = _emitTypeNames(parameterTypes, parameters, |
| 2947 nameType: nameType, hoistType: hoistType); | 2956 nameType: nameType, hoistType: hoistType); |
| 2948 | 2957 |
| 2949 List<JS.Expression> typeParts; | 2958 List<JS.Expression> typeParts; |
| 2950 if (namedTypes.isNotEmpty) { | 2959 if (namedTypes.isNotEmpty) { |
| 2951 assert(optionalTypes.isEmpty); | 2960 assert(optionalTypes.isEmpty); |
| 2952 // TODO(vsm): Pass in annotations here as well. | 2961 // TODO(vsm): Pass in annotations here as well. |
| 2953 var na = _emitTypeProperties(namedTypes); | 2962 var na = _emitTypeProperties(namedTypes); |
| 2954 typeParts = [rt, ra, na]; | 2963 typeParts = [rt, ra, na]; |
| 2955 } else if (optionalTypes.isNotEmpty) { | 2964 } else if (optionalTypes.isNotEmpty) { |
| (...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5831 if (targetIdentifier.staticElement is! PrefixElement) return false; | 5840 if (targetIdentifier.staticElement is! PrefixElement) return false; |
| 5832 var prefix = targetIdentifier.staticElement as PrefixElement; | 5841 var prefix = targetIdentifier.staticElement as PrefixElement; |
| 5833 | 5842 |
| 5834 // The library the prefix is referring to must come from a deferred import. | 5843 // The library the prefix is referring to must come from a deferred import. |
| 5835 var containingLibrary = resolutionMap | 5844 var containingLibrary = resolutionMap |
| 5836 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) | 5845 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) |
| 5837 .library; | 5846 .library; |
| 5838 var imports = containingLibrary.getImportsWithPrefix(prefix); | 5847 var imports = containingLibrary.getImportsWithPrefix(prefix); |
| 5839 return imports.length == 1 && imports[0].isDeferred; | 5848 return imports.length == 1 && imports[0].isDeferred; |
| 5840 } | 5849 } |
| OLD | NEW |