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

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

Issue 2568723007: Create Namer and Emitter on codegen start. (Closed)
Patch Set: Small fix. Created 4 years 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.full_emitter; 5 part of dart2js.js_emitter.full_emitter;
6 6
7 class NsmEmitter extends CodeEmitterHelper { 7 class NsmEmitter extends CodeEmitterHelper {
8 final ClosedWorld closedWorld;
8 final List<Selector> trivialNsmHandlers = <Selector>[]; 9 final List<Selector> trivialNsmHandlers = <Selector>[];
9 10
11 NsmEmitter(this.closedWorld);
12
10 /// If this is true then we can generate the noSuchMethod handlers at startup 13 /// If this is true then we can generate the noSuchMethod handlers at startup
11 /// time, instead of them being emitted as part of the Object class. 14 /// time, instead of them being emitted as part of the Object class.
12 bool get generateTrivialNsmHandlers => true; 15 bool get generateTrivialNsmHandlers => true;
13 16
14 // If we need fewer than this many noSuchMethod handlers we can save space by 17 // If we need fewer than this many noSuchMethod handlers we can save space by
15 // just emitting them in JS, rather than emitting the JS needed to generate 18 // just emitting them in JS, rather than emitting the JS needed to generate
16 // them at run time. 19 // them at run time.
17 static const VERY_FEW_NO_SUCH_METHOD_HANDLERS = 10; 20 static const VERY_FEW_NO_SUCH_METHOD_HANDLERS = 10;
18 21
19 static const MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING = 4; 22 static const MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING = 4;
20 23
21 void emitNoSuchMethodHandlers(AddPropertyFunction addProperty) { 24 void emitNoSuchMethodHandlers(AddPropertyFunction addProperty) {
22 ClassStubGenerator generator = 25 ClassStubGenerator generator = new ClassStubGenerator(
23 new ClassStubGenerator(compiler, namer, backend); 26 namer, backend, codegenWorld, closedWorld,
27 enableMinification: compiler.options.enableMinification);
24 28
25 // Keep track of the JavaScript names we've already added so we 29 // Keep track of the JavaScript names we've already added so we
26 // do not introduce duplicates (bad for code size). 30 // do not introduce duplicates (bad for code size).
27 Map<jsAst.Name, Selector> addedJsNames = 31 Map<jsAst.Name, Selector> addedJsNames =
28 generator.computeSelectorsForNsmHandlers(); 32 generator.computeSelectorsForNsmHandlers();
29 33
30 // Set flag used by generateMethod helper below. If we have very few 34 // Set flag used by generateMethod helper below. If we have very few
31 // handlers we use addProperty for them all, rather than try to generate 35 // handlers we use addProperty for them all, rather than try to generate
32 // them at runtime. 36 // them at runtime.
33 bool haveVeryFewNoSuchMemberHandlers = 37 bool haveVeryFewNoSuchMemberHandlers =
(...skipping 14 matching lines...) Expand all
48 int type = selector.invocationMirrorKind; 52 int type = selector.invocationMirrorKind;
49 if (!haveVeryFewNoSuchMemberHandlers && 53 if (!haveVeryFewNoSuchMemberHandlers &&
50 isTrivialNsmHandler(type, argNames, selector, jsName) && 54 isTrivialNsmHandler(type, argNames, selector, jsName) &&
51 reflectionName == null) { 55 reflectionName == null) {
52 trivialNsmHandlers.add(selector); 56 trivialNsmHandlers.add(selector);
53 } else { 57 } else {
54 StubMethod method = 58 StubMethod method =
55 generator.generateStubForNoSuchMethod(jsName, selector); 59 generator.generateStubForNoSuchMethod(jsName, selector);
56 addProperty(method.name, method.code); 60 addProperty(method.name, method.code);
57 if (reflectionName != null) { 61 if (reflectionName != null) {
58 bool accessible = compiler.closedWorld.allFunctions 62 bool accessible = closedWorld.allFunctions
59 .filter(selector, null) 63 .filter(selector, null)
60 .any((Element e) => backend.isAccessibleByReflection(e)); 64 .any((Element e) => backend.isAccessibleByReflection(e));
61 addProperty( 65 addProperty(
62 namer.asName('+$reflectionName'), js(accessible ? '2' : '0')); 66 namer.asName('+$reflectionName'), js(accessible ? '2' : '0'));
63 } 67 }
64 } 68 }
65 } 69 }
66 } 70 }
67 71
68 // Identify the noSuchMethod handlers that are so simple that we can 72 // Identify the noSuchMethod handlers that are so simple that we can
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 391 }
388 392
389 String get value { 393 String get value {
390 if (_cachedValue == null) { 394 if (_cachedValue == null) {
391 _cachedValue = _computeDiffEncoding(); 395 _cachedValue = _computeDiffEncoding();
392 } 396 }
393 397
394 return _cachedValue; 398 return _cachedValue;
395 } 399 }
396 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698