Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| 11 FunctionElement other) | 11 FunctionElement other) |
| 12 : super.from(name, other, other.enclosingElement); | 12 : super.from(name, other, other.enclosingElement), |
| 13 methodElement = other; | |
| 13 | 14 |
| 14 isInstanceMember() => true; | 15 isInstanceMember() => true; |
| 16 | |
| 17 Element getOutermostEnclosingMemberOrTopLevel() { | |
|
kasperl
2012/09/04 10:50:08
=> methodElement
ngeoffray
2012/09/04 10:53:44
Done.
| |
| 18 return methodElement; | |
| 19 } | |
| 20 | |
| 21 /** | |
| 22 * The [member] this invocation refers to. | |
| 23 */ | |
| 24 Element methodElement; | |
| 15 } | 25 } |
| 16 | 26 |
| 17 /** | 27 /** |
| 18 * Generates the code for all used classes in the program. Static fields (even | 28 * Generates the code for all used classes in the program. Static fields (even |
| 19 * in classes) are ignored, since they can be treated as non-class elements. | 29 * in classes) are ignored, since they can be treated as non-class elements. |
| 20 * | 30 * |
| 21 * The code for the containing (used) methods must exist in the [:universe:]. | 31 * The code for the containing (used) methods must exist in the [:universe:]. |
| 22 */ | 32 */ |
| 23 class CodeEmitterTask extends CompilerTask { | 33 class CodeEmitterTask extends CompilerTask { |
| 24 bool needsInheritFunction = false; | 34 bool needsInheritFunction = false; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null); | 334 // (4) foo$3$c(a, b, c) => foo$4(a, b, c, null); |
| 325 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d); | 335 // (5) foo$3$d(a, b, d) => foo$4(a, b, null, d); |
| 326 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d); | 336 // (6) foo$4$c$d(a, b, c, d) => foo$4(a, b, c, d); |
| 327 // (7) Same as (5). | 337 // (7) Same as (5). |
| 328 // | 338 // |
| 329 // We need to generate a stub for (5) because the order of the | 339 // We need to generate a stub for (5) because the order of the |
| 330 // stub arguments and the real method may be different. | 340 // stub arguments and the real method may be different. |
| 331 | 341 |
| 332 int count = 0; | 342 int count = 0; |
| 333 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; | 343 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; |
| 344 TreeElements elements = | |
| 345 compiler.enqueuer.resolution.getCachedElements(member); | |
| 346 // Note that [elements] may be null for a synthetized [member]. | |
|
kasperl
2012/09/04 10:50:08
Maybe move this comment closer to where you use el
ngeoffray
2012/09/04 10:53:44
Done.
| |
| 347 | |
| 334 parameters.forEachParameter((Element element) { | 348 parameters.forEachParameter((Element element) { |
| 335 String jsName = JsNames.getValid(element.name.slowToString()); | 349 String jsName = JsNames.getValid(element.name.slowToString()); |
| 336 if (count < positionalArgumentCount) { | 350 if (count < positionalArgumentCount) { |
| 337 parametersBuffer[count] = jsName; | 351 parametersBuffer[count] = jsName; |
| 338 argumentsBuffer[count] = jsName; | 352 argumentsBuffer[count] = jsName; |
| 339 } else { | 353 } else { |
| 340 int index = names.indexOf(element.name); | 354 int index = names.indexOf(element.name); |
| 341 if (index != -1) { | 355 if (index != -1) { |
| 342 indexOfLastOptionalArgumentInParameters = count; | 356 indexOfLastOptionalArgumentInParameters = count; |
| 343 // The order of the named arguments is not the same as the | 357 // The order of the named arguments is not the same as the |
| 344 // one in the real method (which is in Dart source order). | 358 // one in the real method (which is in Dart source order). |
| 345 argumentsBuffer[count] = jsName; | 359 argumentsBuffer[count] = jsName; |
| 346 parametersBuffer[selector.positionalArgumentCount + index] = jsName; | 360 parametersBuffer[selector.positionalArgumentCount + index] = jsName; |
| 361 } else if (elements != null && elements.isParameterChecked(element)) { | |
| 362 CodeBuffer argumentBuffer = new CodeBuffer(); | |
| 363 handler.writeConstant(argumentBuffer, SentinelConstant.SENTINEL); | |
| 364 argumentsBuffer[count] = argumentBuffer.toString(); | |
| 347 } else { | 365 } else { |
| 348 Constant value = handler.initialVariableValues[element]; | 366 Constant value = handler.initialVariableValues[element]; |
| 349 if (value == null) { | 367 if (value == null) { |
| 350 argumentsBuffer[count] = NullConstant.JsNull; | 368 argumentsBuffer[count] = NullConstant.JsNull; |
| 351 } else { | 369 } else { |
| 352 if (!value.isNull()) { | 370 if (!value.isNull()) { |
| 353 // If the value is the null constant, we should not pass it | 371 // If the value is the null constant, we should not pass it |
| 354 // down to the native method. | 372 // down to the native method. |
| 355 indexOfLastOptionalArgumentInParameters = count; | 373 indexOfLastOptionalArgumentInParameters = count; |
| 356 } | 374 } |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 sourceName = token.slowToString(); | 1217 sourceName = token.slowToString(); |
| 1200 } | 1218 } |
| 1201 int totalOffset = bufferOffset + offset; | 1219 int totalOffset = bufferOffset + offset; |
| 1202 sourceMapBuilder.addMapping( | 1220 sourceMapBuilder.addMapping( |
| 1203 sourceFile, token.charOffset, sourceName, totalOffset); | 1221 sourceFile, token.charOffset, sourceName, totalOffset); |
| 1204 }); | 1222 }); |
| 1205 } | 1223 } |
| 1206 } | 1224 } |
| 1207 | 1225 |
| 1208 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); | 1226 typedef void DefineMemberFunction(String invocationName, CodeBuffer definition); |
| OLD | NEW |