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

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

Issue 1142293002: Use dart.tearoff helper at tearoff sites (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Clean up conditional 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/core.js ('k') | test/codegen/expect/methods.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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 // For static methods, we add the raw type name, without generics or 1107 // For static methods, we add the raw type name, without generics or
1108 // library prefix. We don't need those because static calls can't use 1108 // library prefix. We don't need those because static calls can't use
1109 // the generic type. 1109 // the generic type.
1110 if (isStatic) { 1110 if (isStatic) {
1111 var dynType = _emitTypeName(fillDynamicTypeArgs(type, types)); 1111 var dynType = _emitTypeName(fillDynamicTypeArgs(type, types));
1112 return new JS.PropertyAccess(dynType, member); 1112 return new JS.PropertyAccess(dynType, member);
1113 } 1113 }
1114 1114
1115 // For instance members, we add implicit-this. 1115 // For instance members, we add implicit-this.
1116 // For method tear-offs, we ensure it's a bound method. 1116 // For method tear-offs, we ensure it's a bound method.
1117 var code = 'this.#'; 1117 var tearOff = element is MethodElement && !inInvocationContext(node);
1118 if (element is MethodElement && !inInvocationContext(node)) { 1118 var code = (tearOff) ? 'dart.tearoff(this, #)' : 'this.#';
Jennifer Messerly 2015/05/20 16:05:17 I don't think we should call this "tearoff" in gen
Leaf 2015/05/20 16:35:17 So you're saying change dart.bind to both bind the
Jennifer Messerly 2015/05/20 16:50:30 err, I think so :). What do we still use "dart.bin
Leaf 2015/05/20 17:05:56 Apparently nothing. Made the switch.
1119 code += '.bind(this)';
1120 }
1121 return js.call(code, member); 1119 return js.call(code, member);
1122 } 1120 }
1123 1121
1124 // initializing formal parameter, e.g. `Point(this.x)` 1122 // initializing formal parameter, e.g. `Point(this.x)`
1125 if (element is ParameterElement && 1123 if (element is ParameterElement &&
1126 element.isInitializingFormal && 1124 element.isInitializingFormal &&
1127 element.isPrivate) { 1125 element.isPrivate) {
1128 /// Rename private names so they don't shadow the private field symbol. 1126 /// Rename private names so they don't shadow the private field symbol.
1129 /// The renamer would handle this, but it would prefer to rename the 1127 /// The renamer would handle this, but it would prefer to rename the
1130 /// temporary used for the private symbol. Instead rename the parameter. 1128 /// temporary used for the private symbol. Instead rename the parameter.
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1982 JS.Expression _emitGet(Expression target, SimpleIdentifier memberId) { 1980 JS.Expression _emitGet(Expression target, SimpleIdentifier memberId) {
1983 var member = memberId.staticElement; 1981 var member = memberId.staticElement;
1984 bool isStatic = member is ExecutableElement && member.isStatic; 1982 bool isStatic = member is ExecutableElement && member.isStatic;
1985 var name = _emitMemberName(memberId.name, 1983 var name = _emitMemberName(memberId.name,
1986 type: getStaticType(target), isStatic: isStatic); 1984 type: getStaticType(target), isStatic: isStatic);
1987 if (rules.isDynamicTarget(target)) { 1985 if (rules.isDynamicTarget(target)) {
1988 return js.call('dart.$DLOAD(#, #)', [_visit(target), name]); 1986 return js.call('dart.$DLOAD(#, #)', [_visit(target), name]);
1989 } 1987 }
1990 1988
1991 String code; 1989 String code;
1992 if (member != null && member is MethodElement) { 1990 if (member != null && member is MethodElement && !isStatic) {
1993 // Tear-off methods: explicitly bind it. 1991 // Tear-off methods: explicitly bind it.
1992 // TODO(leafp): Attach runtime types to these static tearoffs
1994 if (_requiresStaticDispatch(target, memberId.name)) { 1993 if (_requiresStaticDispatch(target, memberId.name)) {
1995 return js.call('dart.#.bind(#)', [name, _visit(target)]); 1994 return js.call('dart.#.bind(#)', [name, _visit(target)]);
1996 } 1995 }
1997 if (isStateless(target, target)) { 1996 code = 'dart.tearoff(#, #)';
1998 return js.call('#.#.bind(#)', [_visit(target), name, _visit(target)]);
Jennifer Messerly 2015/05/20 16:05:17 this makes me a little sad, as we never generate "
Leaf 2015/05/20 16:35:17 Hmm. I actually kind of felt like it was often an
Jennifer Messerly 2015/05/20 16:50:30 yeah, exactly ... in JS it's not something you'd t
1999 }
2000 code = 'dart.bind(#, #)';
2001 } else if (_requiresStaticDispatch(target, memberId.name)) { 1997 } else if (_requiresStaticDispatch(target, memberId.name)) {
2002 return js.call('dart.#(#)', [name, _visit(target)]); 1998 return js.call('dart.#(#)', [name, _visit(target)]);
2003 } else { 1999 } else {
2004 code = '#.#'; 2000 code = '#.#';
2005 } 2001 }
2006 2002
2007 return js.call(code, [_visit(target), name]); 2003 return js.call(code, [_visit(target), name]);
2008 } 2004 }
2009 2005
2010 /// Emits a generic send, like an operator method. 2006 /// Emits a generic send, like an operator method.
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
2566 2562
2567 /// A special kind of element created by the compiler, signifying a temporary 2563 /// A special kind of element created by the compiler, signifying a temporary
2568 /// variable. These objects use instance equality, and should be shared 2564 /// variable. These objects use instance equality, and should be shared
2569 /// everywhere in the tree where they are treated as the same variable. 2565 /// everywhere in the tree where they are treated as the same variable.
2570 class TemporaryVariableElement extends LocalVariableElementImpl { 2566 class TemporaryVariableElement extends LocalVariableElementImpl {
2571 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name); 2567 TemporaryVariableElement.forNode(Identifier name) : super.forNode(name);
2572 2568
2573 int get hashCode => identityHashCode(this); 2569 int get hashCode => identityHashCode(this);
2574 bool operator ==(Object other) => identical(this, other); 2570 bool operator ==(Object other) => identical(this, other);
2575 } 2571 }
OLDNEW
« no previous file with comments | « lib/runtime/dart/core.js ('k') | test/codegen/expect/methods.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698