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

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

Issue 2935933005: fix mixins with factory constructors (Closed)
Patch Set: d Created 3 years, 6 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 1757 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 if (ctors.isEmpty) { 1768 if (ctors.isEmpty) {
1769 var superCall = _superConstructorCall(classElem, className); 1769 var superCall = _superConstructorCall(classElem, className);
1770 List<JS.Statement> body = [_initializeFields(fields)]; 1770 List<JS.Statement> body = [_initializeFields(fields)];
1771 if (superCall != null) body.add(superCall); 1771 if (superCall != null) body.add(superCall);
1772 1772
1773 addConstructor(classElem.unnamedConstructor, 1773 addConstructor(classElem.unnamedConstructor,
1774 _finishConstructorFunction([], new JS.Block(body), isCallable)); 1774 _finishConstructorFunction([], new JS.Block(body), isCallable));
1775 return; 1775 return;
1776 } 1776 }
1777 1777
1778 bool foundConstructor = false;
1778 for (var ctor in ctors) { 1779 for (var ctor in ctors) {
1779 var element = ctor.element; 1780 var element = ctor.element;
1780 if (element.isFactory || _externalOrNative(ctor)) continue; 1781 if (element.isFactory || _externalOrNative(ctor)) continue;
1781 1782
1782 addConstructor( 1783 addConstructor(
1783 element, _emitConstructor(ctor, fields, isCallable, className)); 1784 element, _emitConstructor(ctor, fields, isCallable, className));
1785 foundConstructor = true;
1786 }
1787
1788 // If classElement has only factory constructors, and it can be mixed in,
1789 // then we need to emit a special hidden default constructor for use by
1790 // mixins.
1791 if (!foundConstructor && classElem.supertype.isObject) {
1792 body.add(
1793 js.statement('(#[#] = function() { # }).prototype = #.prototype;', [
1794 className,
1795 _callHelper('mixinNew'),
1796 [_initializeFields(fields)],
1797 className
1798 ]));
1784 } 1799 }
1785 } 1800 }
1786 1801
1787 /// Emits static fields for a class, and initialize them eagerly if possible, 1802 /// Emits static fields for a class, and initialize them eagerly if possible,
1788 /// otherwise define them as lazy properties. 1803 /// otherwise define them as lazy properties.
1789 void _emitStaticFields(List<FieldDeclaration> staticFields, 1804 void _emitStaticFields(List<FieldDeclaration> staticFields,
1790 ClassElement classElem, List<JS.Statement> body) { 1805 ClassElement classElem, List<JS.Statement> body) {
1791 var lazyStatics = staticFields.expand((f) => f.fields.variables).toList(); 1806 var lazyStatics = staticFields.expand((f) => f.fields.variables).toList();
1792 if (lazyStatics.isNotEmpty) { 1807 if (lazyStatics.isNotEmpty) {
1793 body.add(_emitLazyFields(classElem, lazyStatics)); 1808 body.add(_emitLazyFields(classElem, lazyStatics));
(...skipping 4117 matching lines...) Expand 10 before | Expand all | Expand 10 after
5911 if (targetIdentifier.staticElement is! PrefixElement) return false; 5926 if (targetIdentifier.staticElement is! PrefixElement) return false;
5912 var prefix = targetIdentifier.staticElement as PrefixElement; 5927 var prefix = targetIdentifier.staticElement as PrefixElement;
5913 5928
5914 // The library the prefix is referring to must come from a deferred import. 5929 // The library the prefix is referring to must come from a deferred import.
5915 var containingLibrary = resolutionMap 5930 var containingLibrary = resolutionMap
5916 .elementDeclaredByCompilationUnit(target.root as CompilationUnit) 5931 .elementDeclaredByCompilationUnit(target.root as CompilationUnit)
5917 .library; 5932 .library;
5918 var imports = containingLibrary.getImportsWithPrefix(prefix); 5933 var imports = containingLibrary.getImportsWithPrefix(prefix);
5919 return imports.length == 1 && imports[0].isDeferred; 5934 return imports.length == 1 && imports[0].isDeferred;
5920 } 5935 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/lib/sdk/ddc_sdk.sum ('k') | pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698