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

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

Issue 1899373002: Emit forwarding getter/setter when overriding just a getter or setter. (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 | « lib/src/compiler/code_generator.dart ('k') | test/codegen/expect/extensions.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 HashSet; 5 import 'dart:collection' show HashSet;
6
6 import 'package:analyzer/dart/ast/ast.dart' show Identifier; 7 import 'package:analyzer/dart/ast/ast.dart' show Identifier;
7 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9
8 import 'extension_types.dart'; 10 import 'extension_types.dart';
9 11
10 /// We use a storage slot for fields that override or can be overridden by 12 class PropertyOverrideResult {
11 /// getter/setter pairs. 13 final bool foundGetter;
12 HashSet<FieldElement> findFieldsNeedingStorage( 14 final bool foundSetter;
13 Iterable<CompilationUnitElement> units, ExtensionTypeSet extensionTypes) { 15
14 var overrides = new HashSet<FieldElement>(); 16 PropertyOverrideResult(this.foundGetter, this.foundSetter);
15 for (var unit in units) { 17 }
16 for (var cls in unit.types) { 18
17 var superclasses = getSuperclasses(cls); 19 PropertyOverrideResult checkForPropertyOverride(FieldElement field,
18 for (var field in cls.fields) { 20 List<ClassElement> superclasses, ExtensionTypeSet extensionTypes) {
19 if (!field.isSynthetic && !overrides.contains(field)) { 21 bool foundGetter = false;
20 checkForPropertyOverride( 22 bool foundSetter = false;
21 field, superclasses, overrides, extensionTypes); 23
22 } 24 for (var superclass in superclasses) {
23 } 25 // Stop if we reach a native type.
24 } 26 if (extensionTypes.contains(superclass)) break;
27
28 var superprop = getProperty(superclass, field.library, field.name);
29 if (superprop == null) continue;
30
31 var getter = superprop.getter;
32 bool hasGetter = getter != null && !getter.isAbstract;
33 if (hasGetter) foundGetter = true;
34
35 var setter = superprop.setter;
36 bool hasSetter = setter != null && !setter.isAbstract;
37 if (hasSetter) foundSetter = true;
38
39 // Stop if this is an abstract getter/setter
40 // TODO(jmesserly): why were we doing this?
41 if (!hasGetter && !hasSetter) break;
25 } 42 }
26 43
27 return overrides; 44 return new PropertyOverrideResult(foundGetter, foundSetter);
28 }
29
30 void checkForPropertyOverride(
31 FieldElement field,
32 List<ClassElement> superclasses,
33 HashSet<FieldElement> overrides,
34 ExtensionTypeSet extensionTypes) {
35 assert(!field.isSynthetic);
36
37 var library = field.library;
38
39 bool found = false;
40 for (var superclass in superclasses) {
41 var superprop = getProperty(superclass, library, field.name);
42 if (superprop != null) {
43 // If we find an abstract getter/setter pair, stop the search.
44 var getter = superprop.getter;
45 var setter = superprop.setter;
46 if (!extensionTypes.contains(superclass) &&
47 (getter == null || getter.isAbstract) &&
48 (setter == null || setter.isAbstract)) {
49 break;
50 }
51
52 found = true;
53 // Record that the super property is overridden.
54 if (superprop.library == library) overrides.add(superprop);
55 }
56 }
57
58 // If this we found a super property, then this property overrides it.
59 if (found) overrides.add(field);
60 } 45 }
61 46
62 FieldElement getProperty( 47 FieldElement getProperty(
63 ClassElement cls, LibraryElement fromLibrary, String name) { 48 ClassElement cls, LibraryElement fromLibrary, String name) {
64 // Properties from a different library are not accessible. 49 // Properties from a different library are not accessible.
65 if (Identifier.isPrivateName(name) && cls.library != fromLibrary) { 50 if (Identifier.isPrivateName(name) && cls.library != fromLibrary) {
66 return null; 51 return null;
67 } 52 }
68 for (var accessor in cls.accessors) { 53 for (var accessor in cls.accessors) {
69 var prop = accessor.variable; 54 var prop = accessor.variable;
(...skipping 11 matching lines...) Expand all
81 if (mixin != null) result.add(mixin); 66 if (mixin != null) result.add(mixin);
82 } 67 }
83 var supertype = cls.supertype; 68 var supertype = cls.supertype;
84 if (supertype == null) break; 69 if (supertype == null) break;
85 70
86 cls = supertype.element; 71 cls = supertype.element;
87 result.add(cls); 72 result.add(cls);
88 } 73 }
89 return result; 74 return result;
90 } 75 }
OLDNEW
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | test/codegen/expect/extensions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698