Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: pkg/dev_compiler/lib/src/compiler/code_generator.dart

Issue 2641543003: Use "Object" as the reified type of covariant override parameters. (Closed)
Patch Set: Format. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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" for 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 methods whose signature
1833 // did not change.
1834 var needsSignature = true;
1828 var inheritedElement = lookup(name, currentLibrary); 1835 var inheritedElement = lookup(name, currentLibrary);
1829 if (inheritedElement != null && inheritedElement.type == element.type) { 1836 if (inheritedElement != null) {
1830 continue; 1837 if (inheritedElement is MethodElement) {
1838 needsSignature =
1839 inheritedElement.getReifiedType(objectType) != reifiedType;
1840 } else {
1841 needsSignature = inheritedElement.type != reifiedType;
1842 }
1831 } 1843 }
1832 var memberName = _declareMemberName(element); 1844
1833 var property = new JS.Property(memberName, type); 1845 if (needsSignature) {
1834 tMember.add(property); 1846 var memberName = _declareMemberName(element);
1835 // TODO(vsm): Why do we need this? 1847 var property = new JS.Property(memberName, type);
1836 if (node.isStatic && !node.isGetter && !node.isSetter) { 1848 tMember.add(property);
1837 sNames.add(memberName); 1849 // TODO(vsm): Why do we need this?
1850 if (node.isStatic && !node.isGetter && !node.isSetter) {
1851 sNames.add(memberName);
1852 }
1838 } 1853 }
1839 } 1854 }
1840 1855
1841 var tInstanceFields = <JS.Property>[]; 1856 var tInstanceFields = <JS.Property>[];
1842 var tStaticFields = <JS.Property>[]; 1857 var tStaticFields = <JS.Property>[];
1843 for (FieldDeclaration node in fields) { 1858 for (FieldDeclaration node in fields) {
1844 for (VariableDeclaration field in node.fields.variables) { 1859 for (VariableDeclaration field in node.fields.variables) {
1845 var element = field.element as FieldElement; 1860 var element = field.element as FieldElement;
1846 var memberName = _declareMemberName(element.getter); 1861 var memberName = _declareMemberName(element.getter);
1847 var type = _emitAnnotatedType(element.type, node.metadata); 1862 var type = _emitAnnotatedType(element.type, node.metadata);
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
2901 {List<FormalParameter> parameters, 2916 {List<FormalParameter> parameters,
2902 bool lowerTypedef: false, 2917 bool lowerTypedef: false,
2903 bool nameType: true, 2918 bool nameType: true,
2904 bool hoistType: true, 2919 bool hoistType: true,
2905 definite: false}) { 2920 definite: false}) {
2906 var parts = _emitFunctionTypeParts(type, 2921 var parts = _emitFunctionTypeParts(type,
2907 parameters: parameters, 2922 parameters: parameters,
2908 lowerTypedef: lowerTypedef, 2923 lowerTypedef: lowerTypedef,
2909 nameType: nameType, 2924 nameType: nameType,
2910 hoistType: hoistType); 2925 hoistType: hoistType);
2911 var helper = (definite) ? 'definiteFunctionType' : 'functionType'; 2926 var helper = definite ? 'definiteFunctionType' : 'functionType';
2912 var fullType = _callHelper('${helper}(#)', [parts]); 2927 var fullType = _callHelper('${helper}(#)', [parts]);
2913 if (!nameType) return fullType; 2928 if (!nameType) return fullType;
2914 return _typeTable.nameType(type, fullType, 2929 return _typeTable.nameType(type, fullType,
2915 hoistType: hoistType, definite: definite); 2930 hoistType: hoistType, definite: definite);
2916 } 2931 }
2917 2932
2918 JS.Expression _emitAnnotatedFunctionType( 2933 JS.Expression _emitAnnotatedFunctionType(
2919 FunctionType type, List<Annotation> metadata, 2934 FunctionType type, List<Annotation> metadata,
2920 {List<FormalParameter> parameters, 2935 {List<FormalParameter> parameters,
2921 bool lowerTypedef: false, 2936 bool lowerTypedef: false,
(...skipping 14 matching lines...) Expand all
2936 List<JS.Expression> _emitFunctionTypeParts(FunctionType type, 2951 List<JS.Expression> _emitFunctionTypeParts(FunctionType type,
2937 {List<FormalParameter> parameters, 2952 {List<FormalParameter> parameters,
2938 bool lowerTypedef: false, 2953 bool lowerTypedef: false,
2939 bool nameType: true, 2954 bool nameType: true,
2940 bool hoistType: true}) { 2955 bool hoistType: true}) {
2941 var parameterTypes = type.normalParameterTypes; 2956 var parameterTypes = type.normalParameterTypes;
2942 var optionalTypes = type.optionalParameterTypes; 2957 var optionalTypes = type.optionalParameterTypes;
2943 var namedTypes = type.namedParameterTypes; 2958 var namedTypes = type.namedParameterTypes;
2944 var rt = 2959 var rt =
2945 _emitType(type.returnType, nameType: nameType, hoistType: hoistType); 2960 _emitType(type.returnType, nameType: nameType, hoistType: hoistType);
2961
2946 var ra = _emitTypeNames(parameterTypes, parameters, 2962 var ra = _emitTypeNames(parameterTypes, parameters,
2947 nameType: nameType, hoistType: hoistType); 2963 nameType: nameType, hoistType: hoistType);
2948 2964
2949 List<JS.Expression> typeParts; 2965 List<JS.Expression> typeParts;
2950 if (namedTypes.isNotEmpty) { 2966 if (namedTypes.isNotEmpty) {
2951 assert(optionalTypes.isEmpty); 2967 assert(optionalTypes.isEmpty);
2952 // TODO(vsm): Pass in annotations here as well. 2968 // TODO(vsm): Pass in annotations here as well.
2953 var na = _emitTypeProperties(namedTypes); 2969 var na = _emitTypeProperties(namedTypes);
2954 typeParts = [rt, ra, na]; 2970 typeParts = [rt, ra, na];
2955 } else if (optionalTypes.isNotEmpty) { 2971 } else if (optionalTypes.isNotEmpty) {
(...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after
5831 if (targetIdentifier.staticElement is! PrefixElement) return false; 5847 if (targetIdentifier.staticElement is! PrefixElement) return false;
5832 var prefix = targetIdentifier.staticElement as PrefixElement; 5848 var prefix = targetIdentifier.staticElement as PrefixElement;
5833 5849
5834 // The library the prefix is referring to must come from a deferred import. 5850 // The library the prefix is referring to must come from a deferred import.
5835 var containingLibrary = resolutionMap 5851 var containingLibrary = resolutionMap
5836 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5852 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5837 .library; 5853 .library;
5838 var imports = containingLibrary.getImportsWithPrefix(prefix); 5854 var imports = containingLibrary.getImportsWithPrefix(prefix);
5839 return imports.length == 1 && imports[0].isDeferred; 5855 return imports.length == 1 && imports[0].isDeferred;
5840 } 5856 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/member.dart ('k') | pkg/dev_compiler/test/browser/language_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698