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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 */ | 707 */ |
| 708 void addInstanceMember(Element member, ClassBuilder builder) { | 708 void addInstanceMember(Element member, ClassBuilder builder) { |
| 709 assert(invariant(member, member.isDeclaration)); | 709 assert(invariant(member, member.isDeclaration)); |
| 710 // TODO(floitsch): we don't need to deal with members of | 710 // TODO(floitsch): we don't need to deal with members of |
| 711 // uninstantiated classes, that have been overwritten by subclasses. | 711 // uninstantiated classes, that have been overwritten by subclasses. |
| 712 | 712 |
| 713 if (member.isFunction() | 713 if (member.isFunction() |
| 714 || member.isGenerativeConstructorBody() | 714 || member.isGenerativeConstructorBody() |
| 715 || member.isAccessor()) { | 715 || member.isAccessor()) { |
| 716 if (member.isAbstract(compiler)) return; | 716 if (member.isAbstract(compiler)) return; |
| 717 js.Expression code = compiler.codegenWorld.generatedCode[member]; | 717 JavaScriptBackend backend = compiler.backend; |
|
karlklose
2013/02/08 11:44:53
How about making this a getter? I count 19 occurre
| |
| 718 js.Expression code = backend.generatedCode[member]; | |
| 718 if (code == null) return; | 719 if (code == null) return; |
| 719 builder.addProperty(namer.getName(member), code); | 720 builder.addProperty(namer.getName(member), code); |
| 720 code = compiler.codegenWorld.generatedBailoutCode[member]; | 721 code = backend.generatedBailoutCode[member]; |
| 721 if (code != null) { | 722 if (code != null) { |
| 722 builder.addProperty(namer.getBailoutName(member), code); | 723 builder.addProperty(namer.getBailoutName(member), code); |
| 723 } | 724 } |
| 724 FunctionElement function = member; | 725 FunctionElement function = member; |
| 725 FunctionSignature parameters = function.computeSignature(compiler); | 726 FunctionSignature parameters = function.computeSignature(compiler); |
| 726 if (!parameters.optionalParameters.isEmpty) { | 727 if (!parameters.optionalParameters.isEmpty) { |
| 727 addParameterStubs(member, builder.addProperty); | 728 addParameterStubs(member, builder.addProperty); |
| 728 } | 729 } |
| 729 } else if (!member.isField()) { | 730 } else if (!member.isField()) { |
| 730 compiler.internalError('unexpected kind: "${member.kind}"', | 731 compiler.internalError('unexpected kind: "${member.kind}"', |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1385 void emitStaticFunction(CodeBuffer buffer, | 1386 void emitStaticFunction(CodeBuffer buffer, |
| 1386 String name, | 1387 String name, |
| 1387 js.Expression functionExpression) { | 1388 js.Expression functionExpression) { |
| 1388 js.Expression assignment = | 1389 js.Expression assignment = |
| 1389 js.assign(js.use(isolateProperties).dot(name), functionExpression); | 1390 js.assign(js.use(isolateProperties).dot(name), functionExpression); |
| 1390 buffer.add(js.prettyPrint(assignment, compiler)); | 1391 buffer.add(js.prettyPrint(assignment, compiler)); |
| 1391 buffer.add('$N$n'); | 1392 buffer.add('$N$n'); |
| 1392 } | 1393 } |
| 1393 | 1394 |
| 1394 void emitStaticFunctions(CodeBuffer buffer) { | 1395 void emitStaticFunctions(CodeBuffer buffer) { |
| 1396 JavaScriptBackend backend = compiler.backend; | |
| 1395 bool isStaticFunction(Element element) => | 1397 bool isStaticFunction(Element element) => |
| 1396 !element.isInstanceMember() && !element.isField(); | 1398 !element.isInstanceMember() && !element.isField(); |
| 1397 | 1399 |
| 1398 Iterable<Element> elements = | 1400 Iterable<Element> elements = |
| 1399 compiler.codegenWorld.generatedCode.keys.where(isStaticFunction); | 1401 backend.generatedCode.keys.where(isStaticFunction); |
| 1400 Set<Element> pendingElementsWithBailouts = | 1402 Set<Element> pendingElementsWithBailouts = |
| 1401 compiler.codegenWorld.generatedBailoutCode.keys | 1403 backend.generatedBailoutCode.keys |
| 1402 .where(isStaticFunction) | 1404 .where(isStaticFunction) |
| 1403 .toSet(); | 1405 .toSet(); |
| 1404 | 1406 |
| 1405 for (Element element in Elements.sortedByPosition(elements)) { | 1407 for (Element element in Elements.sortedByPosition(elements)) { |
| 1406 js.Expression code = compiler.codegenWorld.generatedCode[element]; | 1408 js.Expression code = backend.generatedCode[element]; |
| 1407 emitStaticFunction(buffer, namer.getName(element), code); | 1409 emitStaticFunction(buffer, namer.getName(element), code); |
| 1408 js.Expression bailoutCode = | 1410 js.Expression bailoutCode = backend.generatedBailoutCode[element]; |
| 1409 compiler.codegenWorld.generatedBailoutCode[element]; | |
| 1410 if (bailoutCode != null) { | 1411 if (bailoutCode != null) { |
| 1411 pendingElementsWithBailouts.remove(element); | 1412 pendingElementsWithBailouts.remove(element); |
| 1412 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); | 1413 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); |
| 1413 } | 1414 } |
| 1414 } | 1415 } |
| 1415 | 1416 |
| 1416 // Is it possible the primary function was inlined but the bailout was not? | 1417 // Is it possible the primary function was inlined but the bailout was not? |
| 1417 for (Element element in | 1418 for (Element element in |
| 1418 Elements.sortedByPosition(pendingElementsWithBailouts)) { | 1419 Elements.sortedByPosition(pendingElementsWithBailouts)) { |
| 1419 js.Expression bailoutCode = | 1420 js.Expression bailoutCode = backend.generatedBailoutCode[element]; |
| 1420 compiler.codegenWorld.generatedBailoutCode[element]; | |
| 1421 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); | 1421 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); |
| 1422 } | 1422 } |
| 1423 } | 1423 } |
| 1424 | 1424 |
| 1425 void emitStaticFunctionGetters(CodeBuffer buffer) { | 1425 void emitStaticFunctionGetters(CodeBuffer buffer) { |
| 1426 Set<FunctionElement> functionsNeedingGetter = | 1426 Set<FunctionElement> functionsNeedingGetter = |
| 1427 compiler.codegenWorld.staticFunctionsNeedingGetter; | 1427 compiler.codegenWorld.staticFunctionsNeedingGetter; |
| 1428 for (FunctionElement element in | 1428 for (FunctionElement element in |
| 1429 Elements.sortedByPosition(functionsNeedingGetter)) { | 1429 Elements.sortedByPosition(functionsNeedingGetter)) { |
| 1430 // The static function does not have the correct name. Since | 1430 // The static function does not have the correct name. Since |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1716 buffer.add(js.prettyPrint(init, compiler)); | 1716 buffer.add(js.prettyPrint(init, compiler)); |
| 1717 buffer.add('$N'); | 1717 buffer.add('$N'); |
| 1718 }); | 1718 }); |
| 1719 } | 1719 } |
| 1720 } | 1720 } |
| 1721 | 1721 |
| 1722 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { | 1722 void emitLazilyInitializedStaticFields(CodeBuffer buffer) { |
| 1723 ConstantHandler handler = compiler.constantHandler; | 1723 ConstantHandler handler = compiler.constantHandler; |
| 1724 List<VariableElement> lazyFields = | 1724 List<VariableElement> lazyFields = |
| 1725 handler.getLazilyInitializedFieldsForEmission(); | 1725 handler.getLazilyInitializedFieldsForEmission(); |
| 1726 JavaScriptBackend backend = compiler.backend; | |
| 1726 if (!lazyFields.isEmpty) { | 1727 if (!lazyFields.isEmpty) { |
| 1727 needsLazyInitializer = true; | 1728 needsLazyInitializer = true; |
| 1728 for (VariableElement element in Elements.sortedByPosition(lazyFields)) { | 1729 for (VariableElement element in Elements.sortedByPosition(lazyFields)) { |
| 1729 assert(compiler.codegenWorld.generatedBailoutCode[element] == null); | 1730 assert(backend.generatedBailoutCode[element] == null); |
| 1730 js.Expression code = compiler.codegenWorld.generatedCode[element]; | 1731 js.Expression code = backend.generatedCode[element]; |
| 1731 assert(code != null); | 1732 assert(code != null); |
| 1732 // The code only computes the initial value. We build the lazy-check | 1733 // The code only computes the initial value. We build the lazy-check |
| 1733 // here: | 1734 // here: |
| 1734 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); | 1735 // lazyInitializer(prototype, 'name', fieldName, getterName, initial); |
| 1735 // The name is used for error reporting. The 'initial' must be a | 1736 // The name is used for error reporting. The 'initial' must be a |
| 1736 // closure that constructs the initial value. | 1737 // closure that constructs the initial value. |
| 1737 List<js.Expression> arguments = <js.Expression>[]; | 1738 List<js.Expression> arguments = <js.Expression>[]; |
| 1738 arguments.add(js.use(isolateProperties)); | 1739 arguments.add(js.use(isolateProperties)); |
| 1739 arguments.add(js.string(element.name.slowToString())); | 1740 arguments.add(js.string(element.name.slowToString())); |
| 1740 arguments.add(js.string(namer.getName(element))); | 1741 arguments.add(js.string(namer.getName(element))); |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2349 """; | 2350 """; |
| 2350 const String HOOKS_API_USAGE = """ | 2351 const String HOOKS_API_USAGE = """ |
| 2351 // The code supports the following hooks: | 2352 // The code supports the following hooks: |
| 2352 // dartPrint(message) - if this function is defined it is called | 2353 // dartPrint(message) - if this function is defined it is called |
| 2353 // instead of the Dart [print] method. | 2354 // instead of the Dart [print] method. |
| 2354 // dartMainRunner(main) - if this function is defined, the Dart [main] | 2355 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 2355 // method will not be invoked directly. | 2356 // method will not be invoked directly. |
| 2356 // Instead, a closure that will invoke [main] is | 2357 // Instead, a closure that will invoke [main] is |
| 2357 // passed to [dartMainRunner]. | 2358 // passed to [dartMainRunner]. |
| 2358 """; | 2359 """; |
| OLD | NEW |