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

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

Issue 1968193002: avoid spread args (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 import 'dart:math' show min, max; 6 import 'dart:math' show min, max;
7 7
8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 8 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 10 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 JS.Statement visitClassTypeAlias(ClassTypeAlias node) { 549 JS.Statement visitClassTypeAlias(ClassTypeAlias node) {
550 ClassElement element = node.element; 550 ClassElement element = node.element;
551 551
552 // Forward all generative constructors from the base class. 552 // Forward all generative constructors from the base class.
553 var methods = <JS.Method>[]; 553 var methods = <JS.Method>[];
554 554
555 var supertype = element.supertype; 555 var supertype = element.supertype;
556 if (!supertype.isObject) { 556 if (!supertype.isObject) {
557 for (var ctor in element.constructors) { 557 for (var ctor in element.constructors) {
558 var parentCtor = supertype.lookUpConstructor(ctor.name, ctor.library); 558 var parentCtor = supertype.lookUpConstructor(ctor.name, ctor.library);
559 var fun = js.call('function() { super.#(...arguments); }', 559 // TODO(jmesserly): this avoids spread args for perf. Revisit.
560 [_constructorName(parentCtor)]) as JS.Fun; 560 var jsParams = <JS.Identifier>[];
561 for (var p in ctor.parameters) {
562 if (p.parameterKind != ParameterKind.NAMED) {
563 jsParams.add(new JS.Identifier(p.name));
564 } else {
565 jsParams.add(new JS.TemporaryId('namedArgs'));
566 break;
567 }
568 }
569 var fun = js.call('function(#) { super.#(#); }',
570 [jsParams, _constructorName(parentCtor), jsParams]) as JS.Fun;
561 methods.add(new JS.Method(_constructorName(ctor), fun)); 571 methods.add(new JS.Method(_constructorName(ctor), fun));
562 } 572 }
563 } 573 }
564 574
565 var classExpr = _emitClassExpression(element, methods); 575 var classExpr = _emitClassExpression(element, methods);
566 576
567 var typeFormals = element.typeParameters; 577 var typeFormals = element.typeParameters;
568 if (typeFormals.isNotEmpty) { 578 if (typeFormals.isNotEmpty) {
569 return _defineClassTypeArguments( 579 return _defineClassTypeArguments(
570 element, typeFormals, new JS.ClassDeclaration(classExpr)); 580 element, typeFormals, new JS.ClassDeclaration(classExpr));
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8 1383 // TODO(jmesserly): we'll need to rethink this once the ES6 spec and V8
1374 // settles. See <https://github.com/dart-lang/dev_compiler/issues/51>. 1384 // settles. See <https://github.com/dart-lang/dev_compiler/issues/51>.
1375 // Performance of this pattern is likely to be bad. 1385 // Performance of this pattern is likely to be bad.
1376 name = _propertyName('constructor'); 1386 name = _propertyName('constructor');
1377 // Mark the parameter as no-rename. 1387 // Mark the parameter as no-rename.
1378 body = js.statement('''{ 1388 body = js.statement('''{
1379 // Get the class name for this instance. 1389 // Get the class name for this instance.
1380 let name = this.constructor.name; 1390 let name = this.constructor.name;
1381 // Call the default constructor. 1391 // Call the default constructor.
1382 let result = void 0; 1392 let result = void 0;
1383 if (name in this) result = this[name](...arguments); 1393 if (name in this) result = this[name].apply(this, arguments);
1384 return result === void 0 ? this : result; 1394 return result === void 0 ? this : result;
1385 }''') as JS.Block; 1395 }''') as JS.Block;
1386 } else { 1396 } else {
1387 var savedFunction = _currentFunction; 1397 var savedFunction = _currentFunction;
1388 _currentFunction = node.body; 1398 _currentFunction = node.body;
1389 body = _emitConstructorBody(node, fields, virtualFields); 1399 body = _emitConstructorBody(node, fields, virtualFields);
1390 _currentFunction = savedFunction; 1400 _currentFunction = savedFunction;
1391 } 1401 }
1392 1402
1393 // We generate constructors as initializer methods in the class; 1403 // We generate constructors as initializer methods in the class;
(...skipping 3034 matching lines...) Expand 10 before | Expand all | Expand 10 after
4428 } 4438 }
4429 4439
4430 bool isLibraryPrefix(Expression node) => 4440 bool isLibraryPrefix(Expression node) =>
4431 node is SimpleIdentifier && node.staticElement is PrefixElement; 4441 node is SimpleIdentifier && node.staticElement is PrefixElement;
4432 4442
4433 LibraryElement _getLibrary(AnalysisContext c, String uri) => 4443 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
4434 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 4444 c.computeLibraryElement(c.sourceFactory.forUri(uri));
4435 4445
4436 bool _isDartRuntime(LibraryElement l) => 4446 bool _isDartRuntime(LibraryElement l) =>
4437 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 4447 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698