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

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

Issue 1895903002: emit 'this.x' when 'super.x' accesses a field (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | test/codegen/expect/language-all.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 import 'dart:collection' show HashMap, HashSet; 5 import 'dart:collection' show HashMap, HashSet;
6 6
7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 7 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
8 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType; 8 import 'package:analyzer/dart/ast/token.dart' show Token, TokenType;
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 3024 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 } 3035 }
3036 3036
3037 // If the target could be `null`, we need static dispatch. 3037 // If the target could be `null`, we need static dispatch.
3038 // If the target may be an extension type, we also use static dispatch 3038 // If the target may be an extension type, we also use static dispatch
3039 // as we don't symbolize object properties like hashCode. 3039 // as we don't symbolize object properties like hashCode.
3040 return isNullable(target) || 3040 return isNullable(target) ||
3041 (_extensionTypes.contains(type.element) && target is! SuperExpression); 3041 (_extensionTypes.contains(type.element) && target is! SuperExpression);
3042 } 3042 }
3043 3043
3044 /// Shared code for [PrefixedIdentifier] and [PropertyAccess]. 3044 /// Shared code for [PrefixedIdentifier] and [PropertyAccess].
3045 JS.Expression _emitGet(Expression target, SimpleIdentifier memberId) { 3045 JS.Expression _emitGet(Expression target, SimpleIdentifier memberId) {
Jennifer Messerly 2016/04/18 21:10:12 Suggestion: if you want to rename this "_emitPrope
Harry Terkelsen 2016/04/18 21:28:58 Done.
3046 var member = memberId.staticElement; 3046 var member = memberId.staticElement;
3047 if (member is PropertyAccessorElement) { 3047 if (member is PropertyAccessorElement) {
3048 member = (member as PropertyAccessorElement).variable; 3048 member = (member as PropertyAccessorElement).variable;
3049 } 3049 }
3050 bool isStatic = member is ClassMemberElement && member.isStatic; 3050 bool isStatic = member is ClassMemberElement && member.isStatic;
3051 var name = _emitMemberName(memberId.name, 3051 var name = _emitMemberName(memberId.name,
3052 type: getStaticType(target), isStatic: isStatic); 3052 type: getStaticType(target), isStatic: isStatic);
3053 if (DynamicInvoke.get(target)) { 3053 if (DynamicInvoke.get(target)) {
3054 return js.call('dart.dload(#, #)', [_visit(target), name]); 3054 return js.call('dart.dload(#, #)', [_visit(target), name]);
3055 } 3055 }
3056 3056
3057 if (target is SuperExpression &&
3058 member is FieldElement &&
3059 member.getter.isSynthetic &&
3060 member.setter.isSynthetic) {
Jennifer Messerly 2016/04/18 21:10:12 Oops I didn't reply fast enough to the original th
Jennifer Messerly 2016/04/18 21:20:13 Ah, so you should be able to just check `!member.i
Harry Terkelsen 2016/04/18 21:28:58 On final fields, setter is null. I'll just check i
3061 // If super.x is actually a field, then x is an instance property since
3062 // subclasses cannot override x.
3063 return js.call('this.#', [name]);
3064 }
3065
3057 String code; 3066 String code;
3058 if (member != null && member is MethodElement && !isStatic) { 3067 if (member != null && member is MethodElement && !isStatic) {
3059 // Tear-off methods: explicitly bind it. 3068 // Tear-off methods: explicitly bind it.
3060 if (target is SuperExpression) { 3069 if (target is SuperExpression) {
3061 return js.call('dart.bind(this, #, #.#)', [name, _visit(target), name]); 3070 return js.call('dart.bind(this, #, #.#)', [name, _visit(target), name]);
3062 } else if (_requiresStaticDispatch(target, memberId.name)) { 3071 } else if (_requiresStaticDispatch(target, memberId.name)) {
3063 var type = member.type; 3072 var type = member.type;
3064 var clos = js.call('dart.#.bind(#)', [name, _visit(target)]); 3073 var clos = js.call('dart.#.bind(#)', [name, _visit(target)]);
3065 return js.call('dart.fn(#, #)', [clos, _emitFunctionTypeParts(type)]); 3074 return js.call('dart.fn(#, #)', [clos, _emitFunctionTypeParts(type)]);
3066 } 3075 }
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
3749 } 3758 }
3750 3759
3751 bool isLibraryPrefix(Expression node) => 3760 bool isLibraryPrefix(Expression node) =>
3752 node is SimpleIdentifier && node.staticElement is PrefixElement; 3761 node is SimpleIdentifier && node.staticElement is PrefixElement;
3753 3762
3754 LibraryElement _getLibrary(AnalysisContext c, String uri) => 3763 LibraryElement _getLibrary(AnalysisContext c, String uri) =>
3755 c.computeLibraryElement(c.sourceFactory.forUri(uri)); 3764 c.computeLibraryElement(c.sourceFactory.forUri(uri));
3756 3765
3757 bool _isDartRuntime(LibraryElement l) => 3766 bool _isDartRuntime(LibraryElement l) =>
3758 l.isInSdk && l.source.uri.toString() == 'dart:_runtime'; 3767 l.isInSdk && l.source.uri.toString() == 'dart:_runtime';
OLDNEW
« no previous file with comments | « no previous file | test/codegen/expect/language-all.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698