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

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

Issue 1152583002: Add constructors to signatures (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: 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
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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 classElem.lookUpInheritedConcreteMethod(name, currentLibrary); 596 classElem.lookUpInheritedConcreteMethod(name, currentLibrary);
597 if (inheritedElement != null && 597 if (inheritedElement != null &&
598 inheritedElement.type == element.type) continue; 598 inheritedElement.type == element.type) continue;
599 var unary = node.parameters.parameters.isEmpty; 599 var unary = node.parameters.parameters.isEmpty;
600 var memberName = _emitMemberName(name, 600 var memberName = _emitMemberName(name,
601 type: cType, unary: unary, isStatic: node.isStatic); 601 type: cType, unary: unary, isStatic: node.isStatic);
602 var parts = 602 var parts =
603 _emitFunctionTypeParts(element.type, dynamicIsBottom: false); 603 _emitFunctionTypeParts(element.type, dynamicIsBottom: false);
604 var property = 604 var property =
605 new JS.Property(memberName, new JS.ArrayInitializer(parts)); 605 new JS.Property(memberName, new JS.ArrayInitializer(parts));
606 if (node.isStatic) { 606 if (node.isStatic) {
607 tStatics.add(property); 607 tStatics.add(property);
608 sNames.add(memberName); 608 sNames.add(memberName);
609 } else tMethods.add(property); 609 } else tMethods.add(property);
610 } 610 }
611 } 611 }
612 var tCtors = [];
613 for (ConstructorDeclaration node in ctors) {
614 var memberName = _constructorName(classElem.name, node.name);
615 var element = node.element;
616 var parts =
617 _emitFunctionTypeParts(element.type, dynamicIsBottom: false);
618 var property =
619 new JS.Property(memberName, new JS.ArrayInitializer(parts));
620 tCtors.add(property);
621 }
612 build(name, elements) { 622 build(name, elements) {
613 var o = 623 var o =
614 new JS.ObjectInitializer(elements, vertical: elements.length > 1); 624 new JS.ObjectInitializer(elements, vertical: elements.length > 1);
615 var e = js.call('() => #', o); 625 var e = js.call('() => #', o);
616 var p = new JS.Property(_propertyName(name), e); 626 var p = new JS.Property(_propertyName(name), e);
617 return p; 627 return p;
618 } 628 }
619 var sigFields = []; 629 var sigFields = [];
630 if (!tCtors.isEmpty) sigFields.add(build('constructors', tCtors));
620 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods)); 631 if (!tMethods.isEmpty) sigFields.add(build('methods', tMethods));
621 if (!tStatics.isEmpty) { 632 if (!tStatics.isEmpty) {
622 assert(!sNames.isEmpty); 633 assert(!sNames.isEmpty);
623 var aNames = new JS.Property( 634 var aNames = new JS.Property(
624 _propertyName('names'), new JS.ArrayInitializer(sNames)); 635 _propertyName('names'), new JS.ArrayInitializer(sNames));
625 sigFields.add(build('statics', tStatics)); 636 sigFields.add(build('statics', tStatics));
626 sigFields.add(aNames); 637 sigFields.add(aNames);
627 } 638 }
628
629 if (!sigFields.isEmpty) { 639 if (!sigFields.isEmpty) {
630 var sig = new JS.ObjectInitializer(sigFields); 640 var sig = new JS.ObjectInitializer(sigFields);
631 var classExpr = new JS.Identifier(name); 641 var classExpr = new JS.Identifier(name);
632 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig])); 642 body.add(js.statement('dart.setSignature(#, #);', [classExpr, sig]));
633 } 643 }
634 } 644 }
635 645
636 return _statement(body); 646 return _statement(body);
637 } 647 }
638 648
(...skipping 1963 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 2612
2603 /// A special kind of element created by the compiler, signifying a temporary 2613 /// A special kind of element created by the compiler, signifying a temporary
2604 /// variable. These objects use instance equality, and should be shared 2614 /// variable. These objects use instance equality, and should be shared
2605 /// everywhere in the tree where they are treated as the same variable. 2615 /// everywhere in the tree where they are treated as the same variable.
2606 class TemporaryVariableElement extends LocalVariableElementImpl { 2616 class TemporaryVariableElement extends LocalVariableElementImpl {
2607 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 2617 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
2608 2618
2609 int get hashCode => identityHashCode(this); 2619 int get hashCode => identityHashCode(this);
2610 bool operator ==(Object other) => identical(this, other); 2620 bool operator ==(Object other) => identical(this, other);
2611 } 2621 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698