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/old_emitter/reflection_data_parser.dart

Issue 834133002: dart2js OldEmitter: Small cleanups in output. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 | Annotate | Revision Log
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; 5 part of dart2js.js_emitter;
6 6
7 // TODO(ahe): Share these with js_helper.dart. 7 // TODO(ahe): Share these with js_helper.dart.
8 const FUNCTION_INDEX = 0; 8 const FUNCTION_INDEX = 0;
9 const NAME_INDEX = 1; 9 const NAME_INDEX = 1;
10 const CALL_NAME_INDEX = 2; 10 const CALL_NAME_INDEX = 2;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 var isAccessor = (requiredParameterInfo & 1) === 1; 224 var isAccessor = (requiredParameterInfo & 1) === 1;
225 var isSetter = requiredParameterInfo === 3; 225 var isSetter = requiredParameterInfo === 3;
226 var isGetter = requiredParameterInfo === 1; 226 var isGetter = requiredParameterInfo === 1;
227 var optionalParameterInfo = ${readInt("array", "1")}; 227 var optionalParameterInfo = ${readInt("array", "1")};
228 var optionalParameterCount = optionalParameterInfo >> 1; 228 var optionalParameterCount = optionalParameterInfo >> 1;
229 var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1; 229 var optionalParametersAreNamed = (optionalParameterInfo & 1) === 1;
230 var isIntercepted = 230 var isIntercepted =
231 requiredParameterCount + optionalParameterCount != funcs[0].length; 231 requiredParameterCount + optionalParameterCount != funcs[0].length;
232 var functionTypeIndex = ${readFunctionType("array", "2")}; 232 var functionTypeIndex = ${readFunctionType("array", "2")};
233 var unmangledNameIndex = $unmangledNameIndex; 233 var unmangledNameIndex = $unmangledNameIndex;
234 var isReflectable = array.length > unmangledNameIndex;
ahe 2015/01/05 14:42:25 Decoding "array" is now spread out in the code. Th
floitsch 2015/01/05 14:52:53 I don't think there is a good solution: - we don't
ahe 2015/01/05 15:05:24 I think I know what your answer is going to be, bu
floitsch 2015/01/05 15:07:43 Mostly personal preference. I don't like "if"s all
235 234
236 if (getterStubName) { 235 if (getterStubName) {
237 f = tearOff(funcs, array, isStatic, name, isIntercepted); 236 f = tearOff(funcs, array, isStatic, name, isIntercepted);
238 descriptor[name].\$getter = f; 237 descriptor[name].\$getter = f;
239 f.\$getterStub = true; 238 f.\$getterStub = true;
240 // Used to create an isolate using spawnFunction. 239 // Used to create an isolate using spawnFunction.
241 if (isStatic) #globalFunctions[name] = f; 240 if (isStatic) #globalFunctions[name] = f;
242 originalDescriptor[getterStubName] = descriptor[getterStubName] = f; 241 originalDescriptor[getterStubName] = descriptor[getterStubName] = f;
243 funcs.push(f); 242 funcs.push(f);
244 if (getterStubName) functions.push(getterStubName); 243 if (getterStubName) functions.push(getterStubName);
245 f.\$stubName = getterStubName; 244 f.\$stubName = getterStubName;
246 f.\$callName = null; 245 f.\$callName = null;
247 if (isIntercepted) #interceptedNames[getterStubName] = true; 246 if (isIntercepted) #interceptedNames[getterStubName] = true;
248 } 247 }
249 if (isReflectable) { 248
250 for (var i = 0; i < funcs.length; i++) { 249 if (#isReflectionEnabled) {
251 funcs[i].$reflectableField = 1; 250 var isReflectable = array.length > unmangledNameIndex;
252 funcs[i].$reflectionInfoField = array; 251 if (isReflectable) {
ahe 2015/01/05 14:42:25 I would write: if (!isReflectable) continue; Thi
floitsch 2015/01/05 14:52:53 Adding a "continue" here assumes too much: a- we a
ahe 2015/01/05 15:05:24 I don't know what I was thinking.
252 for (var i = 0; i < funcs.length; i++) {
253 funcs[i].$reflectableField = 1;
254 funcs[i].$reflectionInfoField = array;
255 }
256 var mangledNames = isStatic ? #mangledGlobalNames : #mangledNames;
257 var unmangledName = ${readString("array", "unmangledNameIndex")};
258 // The function is either a getter, a setter, or a method.
259 // If it is a method, it might also have a tear-off closure.
260 // The unmangledName is the same as the getter-name.
261 var reflectionName = unmangledName;
262 if (getterStubName) mangledNames[getterStubName] = reflectionName;
263 if (isSetter) {
264 reflectionName += "=";
265 } else if (!isGetter) {
266 reflectionName += ":" + requiredParameterCount +
267 ":" + optionalParameterCount;
268 }
269 mangledNames[name] = reflectionName;
270 funcs[0].$reflectionNameField = reflectionName;
271 funcs[0].$metadataIndexField = unmangledNameIndex + 1;
272 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0];
253 } 273 }
254 var mangledNames = isStatic ? #mangledGlobalNames : #mangledNames;
255 var unmangledName = ${readString("array", "unmangledNameIndex")};
256 // The function is either a getter, a setter, or a method.
257 // If it is a method, it might also have a tear-off closure.
258 // The unmangledName is the same as the getter-name.
259 var reflectionName = unmangledName;
260 if (getterStubName) mangledNames[getterStubName] = reflectionName;
261 if (isSetter) {
262 reflectionName += "=";
263 } else if (!isGetter) {
264 reflectionName += ":" + requiredParameterCount +
265 ":" + optionalParameterCount;
266 }
267 mangledNames[name] = reflectionName;
268 funcs[0].$reflectionNameField = reflectionName;
269 funcs[0].$metadataIndexField = unmangledNameIndex + 1;
270 if (optionalParameterCount) descriptor[unmangledName + "*"] = funcs[0];
271 } 274 }
272 } 275 }
273 ''', {'globalFunctions' : globalFunctionsAccess, 276 ''', {'globalFunctions' : globalFunctionsAccess,
274 'interceptedNames': interceptedNamesAccess, 277 'interceptedNames': interceptedNamesAccess,
278 'isReflectionEnabled': compiler.mirrorsLibrary != null,
275 'mangledGlobalNames': mangledGlobalNamesAccess, 279 'mangledGlobalNames': mangledGlobalNamesAccess,
276 'mangledNames': mangledNamesAccess}); 280 'mangledNames': mangledNamesAccess});
277 281
278 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend); 282 List<jsAst.Statement> tearOffCode = buildTearOffCode(backend);
279 283
280 jsAst.Statement init = js.statement('''{ 284 jsAst.Statement init = js.statement('''{
281 var functionCounter = 0; 285 var functionCounter = 0;
282 if (!#libraries) #libraries = []; 286 if (!#libraries) #libraries = [];
283 if (!#mangledNames) #mangledNames = map(); 287 if (!#mangledNames) #mangledNames = map();
284 if (!#mangledGlobalNames) #mangledGlobalNames = map(); 288 if (!#mangledGlobalNames) #mangledGlobalNames = map();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 (function() { 563 (function() {
560 var result = $array[$index]; 564 var result = $array[$index];
561 if ($check) { 565 if ($check) {
562 throw new Error( 566 throw new Error(
563 name + ": expected value of type \'$type\' at index " + ($index) + 567 name + ": expected value of type \'$type\' at index " + ($index) +
564 " but got " + (typeof result)); 568 " but got " + (typeof result));
565 } 569 }
566 return result; 570 return result;
567 })()'''; 571 })()''';
568 } 572 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698