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

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1144303003: Use signature inheritance when method types are unchanged (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Remove empty signatures Created 5 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/typed_data.js ('k') | test/browser/runtime_tests.js » ('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 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
8 8
9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 9 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; 10 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator;
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // Emit the signature on the class recording the runtime type information 585 // Emit the signature on the class recording the runtime type information
586 { 586 {
587 var tStatics = []; 587 var tStatics = [];
588 var tMethods = []; 588 var tMethods = [];
589 var sNames = []; 589 var sNames = [];
590 var cType = classElem.type; 590 var cType = classElem.type;
591 for (MethodDeclaration node in methods) { 591 for (MethodDeclaration node in methods) {
592 if (!(node.isSetter || node.isGetter || node.isAbstract)) { 592 if (!(node.isSetter || node.isGetter || node.isAbstract)) {
593 var name = node.name.name; 593 var name = node.name.name;
594 var element = node.element; 594 var element = node.element;
595 var inheritedElement =
596 classElem.lookUpInheritedConcreteMethod(name, currentLibrary);
597 if (inheritedElement != null &&
598 inheritedElement.type == element.type) continue;
595 var unary = node.parameters.parameters.isEmpty; 599 var unary = node.parameters.parameters.isEmpty;
596 var memberName = _emitMemberName(name, 600 var memberName = _emitMemberName(name,
597 type: cType, unary: unary, isStatic: node.isStatic); 601 type: cType, unary: unary, isStatic: node.isStatic);
598 var property = 602 var property =
599 new JS.Property(memberName, _emitTypeName(element.type)); 603 new JS.Property(memberName, _emitTypeName(element.type));
600 if (node.isStatic) { 604 if (node.isStatic) {
601 tStatics.add(property); 605 tStatics.add(property);
602 sNames.add(memberName); 606 sNames.add(memberName);
603 } else tMethods.add(property); 607 } else tMethods.add(property);
604 } 608 }
605 } 609 }
606 build(name, elements) { 610 build(name, elements) {
607 var o = 611 var o =
608 new JS.ObjectInitializer(elements, vertical: elements.length > 1); 612 new JS.ObjectInitializer(elements, vertical: elements.length > 1);
609 var e = js.call('() => #', o); 613 var e = js.call('() => #', o);
610 var p = new JS.Property(_propertyName(name), e); 614 var p = new JS.Property(_propertyName(name), e);
611 return p; 615 return p;
612 } 616 }
613 var sigFields = []; 617 var sigFields = [];
614 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods)); 618 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods));
615 if (!tStatics.isEmpty) { 619 if (!tStatics.isEmpty) {
616 assert(!sNames.isEmpty); 620 assert(!sNames.isEmpty);
617 var aNames = new JS.Property( 621 var aNames = new JS.Property(
618 _propertyName('names'), new JS.ArrayInitializer(sNames)); 622 _propertyName('names'), new JS.ArrayInitializer(sNames));
619 sigFields.add(build('statics', tStatics)); 623 sigFields.add(build('statics', tStatics));
620 sigFields.add(aNames); 624 sigFields.add(aNames);
621 } 625 }
622 626
623 var sig = new JS.ObjectInitializer(sigFields); 627 if (!sigFields.isEmpty) {
624 var classExpr = new JS.Identifier(name); 628 var sig = new JS.ObjectInitializer(sigFields);
625 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig])); 629 var classExpr = new JS.Identifier(name);
630 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig]));
631 }
626 } 632 }
627 633
628 return _statement(body); 634 return _statement(body);
629 } 635 }
630 636
631 JS.Statement _overrideField(FieldElement e) { 637 JS.Statement _overrideField(FieldElement e) {
632 var cls = e.enclosingElement; 638 var cls = e.enclosingElement;
633 return js.statement('dart.virtualField(#, #)', [ 639 return js.statement('dart.virtualField(#, #)', [
634 cls.name, 640 cls.name,
635 _emitMemberName(e.name, type: cls.type) 641 _emitMemberName(e.name, type: cls.type)
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after
2576 2582
2577 /// A special kind of element created by the compiler, signifying a temporary 2583 /// A special kind of element created by the compiler, signifying a temporary
2578 /// variable. These objects use instance equality, and should be shared 2584 /// variable. These objects use instance equality, and should be shared
2579 /// everywhere in the tree where they are treated as the same variable. 2585 /// everywhere in the tree where they are treated as the same variable.
2580 class TemporaryVariableElement extends LocalVariableElementImpl { 2586 class TemporaryVariableElement extends LocalVariableElementImpl {
2581 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 2587 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
2582 2588
2583 int get hashCode => identityHashCode(this); 2589 int get hashCode => identityHashCode(this);
2584 bool operator ==(Object other) => identical(this, other); 2590 bool operator ==(Object other) => identical(this, other);
2585 } 2591 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/typed_data.js ('k') | test/browser/runtime_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698