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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 22455003: Make FunctionTypeMirror and ClosureMirror handle user-defined classes that implement the call opera… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: call is no longer an operator Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 _invokeSetter(reflectee, setterName, value) 590 _invokeSetter(reflectee, setterName, value)
591 native 'ClassMirror_invokeSetter'; 591 native 'ClassMirror_invokeSetter';
592 592
593 static _invokeConstructor(reflectee, constructorName, positionalArguments) 593 static _invokeConstructor(reflectee, constructorName, positionalArguments)
594 native 'ClassMirror_invokeConstructor'; 594 native 'ClassMirror_invokeConstructor';
595 595
596 static _ClassMirror_type_variables(reflectee) 596 static _ClassMirror_type_variables(reflectee)
597 native "ClassMirror_type_variables"; 597 native "ClassMirror_type_variables";
598 } 598 }
599 599
600 // Instances represent user-defined classes that implement the call operator.
600 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 601 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
601 implements FunctionTypeMirror { 602 implements FunctionTypeMirror {
602 _LocalFunctionTypeMirrorImpl(reflectee) : super(reflectee, null); 603 _LocalFunctionTypeMirrorImpl(reflectee, owner) : super(reflectee, owner);
603 604
604 // FunctionTypeMirrors have a simpleName generated from their signature. 605 MethodMirror _callMethod;
605 Symbol _simpleName = null; 606 MethodMirror get callMethod {
606 Symbol get simpleName { 607 if (_callMethod==null) {
607 if (_simpleName == null) { 608 _callMethod = this._FunctionTypeMirror_call_method(_reflectee);
608 _simpleName = _s(_makeSignatureString(returnType, parameters));
609 } 609 }
610 return _simpleName; 610 return _callMethod;
611 } 611 }
612 612
613 TypeMirror _returnType = null; 613 TypeMirror _returnType = null;
614 TypeMirror get returnType { 614 TypeMirror get returnType {
615 if (_returnType == null) { 615 if (_returnType == null) {
616 _returnType = _FunctionTypeMirror_return_type(_reflectee); 616 _returnType = _FunctionTypeMirror_return_type(_reflectee);
617 } 617 }
618 return _returnType; 618 return _returnType;
619 } 619 }
620 620
621 List<ParameterMirror> _parameters = null; 621 List<ParameterMirror> _parameters = null;
622 List<ParameterMirror> get parameters { 622 List<ParameterMirror> get parameters {
623 if (_parameters == null) { 623 if (_parameters == null) {
624 _parameters = _FunctionTypeMirror_parameters(_reflectee); 624 _parameters = _FunctionTypeMirror_parameters(_reflectee);
625 } 625 }
626 return _parameters; 626 return _parameters;
627 } 627 }
628 628
629 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); 629 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'";
630 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>();
631 final Map<Symbol, TypeVariableMirror> typeVariables = const {};
632 630
633 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; 631 MethodMirror _FunctionTypeMirror_call_method(reflectee)
632 native "FunctionTypeMirror_call_method";
634 633
635 static TypeMirror _FunctionTypeMirror_return_type(reflectee) 634 static TypeMirror _FunctionTypeMirror_return_type(reflectee)
636 native "FunctionTypeMirror_return_type"; 635 native "FunctionTypeMirror_return_type";
637 636
638 static List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) 637 static List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee)
639 native "FunctionTypeMirror_parameters"; 638 native "FunctionTypeMirror_parameters";
640 } 639 }
641 640
641 // Instances represent the classes of true closures.
642 class _LocalClosureTypeMirrorImpl extends _LocalFunctionTypeMirrorImpl
643 implements FunctionTypeMirror {
644 _LocalClosureTypeMirrorImpl(reflectee) : super(reflectee, null);
645
646 // FunctionTypeMirrors have a simpleName generated from their signature.
647 Symbol _simpleName = null;
648 Symbol get simpleName {
649 if (_simpleName == null) {
650 _simpleName = _s(_makeSignatureString(returnType, parameters));
651 }
652 return _simpleName;
653 }
654
655 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>();
656 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>();
657 final Map<Symbol, TypeVariableMirror> typeVariables = const {};
658 }
659
642 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 660 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
643 implements DeclarationMirror { 661 implements DeclarationMirror {
644 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); 662 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName);
645 663
646 final _reflectee; 664 final _reflectee;
647 665
648 final Symbol simpleName; 666 final Symbol simpleName;
649 667
650 Symbol _qualifiedName = null; 668 Symbol _qualifiedName = null;
651 Symbol get qualifiedName { 669 Symbol get qualifiedName {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 final bool isTopLevel = true; 754 final bool isTopLevel = true;
737 755
738 SourceLocation get location { 756 SourceLocation get location {
739 throw new UnimplementedError( 757 throw new UnimplementedError(
740 'TypedefMirror.location is not implemented'); 758 'TypedefMirror.location is not implemented');
741 } 759 }
742 760
743 TypeMirror _referent = null; 761 TypeMirror _referent = null;
744 TypeMirror get referent { 762 TypeMirror get referent {
745 if (_referent == null) { 763 if (_referent == null) {
746 return new _LocalFunctionTypeMirrorImpl( 764 return new _LocalClosureTypeMirrorImpl(
747 _TypedefMirror_referent(_reflectee)); 765 _TypedefMirror_referent(_reflectee));
748 } 766 }
749 return _referent; 767 return _referent;
750 } 768 }
751 769
752 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 770 String toString() => "TypedefMirror on '${_n(simpleName)}'";
753 771
754 static _TypedefMirror_referent(_reflectee) 772 static _TypedefMirror_referent(_reflectee)
755 native "TypedefMirror_referent"; 773 native "TypedefMirror_referent";
756 } 774 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror"); 1160 static Expando<ClassMirror> _classMirrorCache = new Expando("ClassMirror");
1143 static ClassMirror reflectClass(Type key) { 1161 static ClassMirror reflectClass(Type key) {
1144 var classMirror = _classMirrorCache[key]; 1162 var classMirror = _classMirrorCache[key];
1145 if (classMirror == null) { 1163 if (classMirror == null) {
1146 classMirror = makeLocalClassMirror(key); 1164 classMirror = makeLocalClassMirror(key);
1147 _classMirrorCache[key] = classMirror; 1165 _classMirrorCache[key] = classMirror;
1148 } 1166 }
1149 return classMirror; 1167 return classMirror;
1150 } 1168 }
1151 } 1169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698