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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/class_stub_generator.dart

Issue 1182913003: Split TypedSelector into Selector and TypeMask. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 6 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class ClassStubGenerator { 7 class ClassStubGenerator {
8 final Namer namer; 8 final Namer namer;
9 final Compiler compiler; 9 final Compiler compiler;
10 final JavaScriptBackend backend; 10 final JavaScriptBackend backend;
(...skipping 30 matching lines...) Expand all
41 return js('function(#, v) { return #.# = v; }', 41 return js('function(#, v) { return #.# = v; }',
42 [args, receiver, fieldName]); 42 [args, receiver, fieldName]);
43 } 43 }
44 44
45 /** 45 /**
46 * Documentation wanted -- johnniwinther 46 * Documentation wanted -- johnniwinther
47 * 47 *
48 * Invariant: [member] must be a declaration element. 48 * Invariant: [member] must be a declaration element.
49 */ 49 */
50 Map<String, jsAst.Expression> generateCallStubsForGetter( 50 Map<String, jsAst.Expression> generateCallStubsForGetter(
51 Element member, Set<Selector> selectors) { 51 Element member, Map<Selector, TypeMaskSet> selectors) {
52 assert(invariant(member, member.isDeclaration)); 52 assert(invariant(member, member.isDeclaration));
53 53
54 // If the method is intercepted, the stub gets the 54 // If the method is intercepted, the stub gets the
55 // receiver explicitely and we need to pass it to the getter call. 55 // receiver explicitely and we need to pass it to the getter call.
56 bool isInterceptedMethod = backend.isInterceptedMethod(member); 56 bool isInterceptedMethod = backend.isInterceptedMethod(member);
57 bool isInterceptorClass = 57 bool isInterceptorClass =
58 backend.isInterceptorClass(member.enclosingClass); 58 backend.isInterceptorClass(member.enclosingClass);
59 59
60 const String receiverArgumentName = r'$receiver'; 60 const String receiverArgumentName = r'$receiver';
61 61
(...skipping 11 matching lines...) Expand all
73 return js('#.#', [receiver, fieldName]); 73 return js('#.#', [receiver, fieldName]);
74 } 74 }
75 } 75 }
76 76
77 Map<String, jsAst.Expression> generatedStubs = <String, jsAst.Expression>{}; 77 Map<String, jsAst.Expression> generatedStubs = <String, jsAst.Expression>{};
78 78
79 // Two selectors may match but differ only in type. To avoid generating 79 // Two selectors may match but differ only in type. To avoid generating
80 // identical stubs for each we track untyped selectors which already have 80 // identical stubs for each we track untyped selectors which already have
81 // stubs. 81 // stubs.
82 Set<Selector> generatedSelectors = new Set<Selector>(); 82 Set<Selector> generatedSelectors = new Set<Selector>();
83 for (Selector selector in selectors) { 83 for (Selector selector in selectors.keys) {
84 if (selector.applies(member, compiler.world)) { 84 if (generatedSelectors.contains(selector)) continue;
85 selector = selector.asUntyped; 85 if (!selector.appliesUnnamed(member, compiler.world)) continue;
86 if (generatedSelectors.contains(selector)) continue; 86 for (TypeMask mask in selectors[selector].masks) {
87 if (mask != null &&
88 !mask.canHit(member, selector, compiler.world)) {
89 continue;
90 }
91
87 generatedSelectors.add(selector); 92 generatedSelectors.add(selector);
88 93
89 String invocationName = namer.invocationName(selector); 94 String invocationName = namer.invocationName(selector);
90 Selector callSelector = new Selector.callClosureFrom(selector); 95 Selector callSelector = new Selector.callClosureFrom(selector);
91 String closureCallName = namer.invocationName(callSelector); 96 String closureCallName = namer.invocationName(callSelector);
92 97
93 List<jsAst.Parameter> parameters = <jsAst.Parameter>[]; 98 List<jsAst.Parameter> parameters = <jsAst.Parameter>[];
94 List<jsAst.Expression> arguments = <jsAst.Expression>[]; 99 List<jsAst.Expression> arguments = <jsAst.Expression>[];
95 if (isInterceptedMethod) { 100 if (isInterceptedMethod) {
96 parameters.add(new jsAst.Parameter(receiverArgumentName)); 101 parameters.add(new jsAst.Parameter(receiverArgumentName));
(...skipping 18 matching lines...) Expand all
115 120
116 Map<String, Selector> computeSelectorsForNsmHandlers() { 121 Map<String, Selector> computeSelectorsForNsmHandlers() {
117 122
118 Map<String, Selector> jsNames = <String, Selector>{}; 123 Map<String, Selector> jsNames = <String, Selector>{};
119 124
120 // Do not generate no such method handlers if there is no class. 125 // Do not generate no such method handlers if there is no class.
121 if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) { 126 if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) {
122 return jsNames; 127 return jsNames;
123 } 128 }
124 129
125 void addNoSuchMethodHandlers(String ignore, Set<Selector> selectors) { 130 void addNoSuchMethodHandlers(String ignore,
131 Map<Selector, TypeMaskSet> selectors) {
126 TypeMask objectSubclassTypeMask = 132 TypeMask objectSubclassTypeMask =
127 new TypeMask.subclass(compiler.objectClass, compiler.world); 133 new TypeMask.subclass(compiler.objectClass, compiler.world);
128 134
129 for (Selector selector in selectors) { 135 for (Selector selector in selectors.keys) {
130 TypeMask mask = selector.mask; 136 TypeMaskSet maskSet = selectors[selector];
131 if (mask == null) mask = objectSubclassTypeMask; 137 for (TypeMask mask in maskSet.masks) {
138 if (mask == null) mask = objectSubclassTypeMask;
132 139
133 if (!mask.needsNoSuchMethodHandling(selector, compiler.world)) { 140 if (mask.needsNoSuchMethodHandling(selector, compiler.world)) {
134 continue; 141 String jsName = namer.invocationMirrorInternalName(selector);
142 jsNames[jsName] = selector;
143 break;
144 }
135 } 145 }
136 String jsName = namer.invocationMirrorInternalName(selector);
137 jsNames[jsName] = selector;
138 } 146 }
139 } 147 }
140 148
141 compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers); 149 compiler.codegenWorld.forEachInvokedName(addNoSuchMethodHandlers);
142 compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers); 150 compiler.codegenWorld.forEachInvokedGetter(addNoSuchMethodHandlers);
143 compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers); 151 compiler.codegenWorld.forEachInvokedSetter(addNoSuchMethodHandlers);
144 return jsNames; 152 return jsNames;
145 } 153 }
146 154
147 StubMethod generateStubForNoSuchMethod(String name, Selector selector) { 155 StubMethod generateStubForNoSuchMethod(String name, Selector selector) {
148 // Values match JSInvocationMirror in js-helper library. 156 // Values match JSInvocationMirror in js-helper library.
149 int type = selector.invocationMirrorKind; 157 int type = selector.invocationMirrorKind;
150 List<String> parameterNames = 158 List<String> parameterNames =
151 new List.generate(selector.argumentCount, (i) => '\$$i'); 159 new List.generate(selector.argumentCount, (i) => '\$$i');
152 160
153 List<jsAst.Expression> argNames = 161 List<jsAst.Expression> argNames =
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 ? function() { 287 ? function() {
280 if (cache === void 0) cache = #tearOff( 288 if (cache === void 0) cache = #tearOff(
281 this, funcs, reflectionInfo, true, [], name).prototype; 289 this, funcs, reflectionInfo, true, [], name).prototype;
282 return cache; 290 return cache;
283 } 291 }
284 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); 292 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
285 }''', {'tearOff': tearOffAccessExpression}); 293 }''', {'tearOff': tearOffAccessExpression});
286 294
287 return <jsAst.Statement>[tearOffGetter, tearOff]; 295 return <jsAst.Statement>[tearOffGetter, tearOff];
288 } 296 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/codegen.dart ('k') | pkg/compiler/lib/src/js_emitter/js_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698