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 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 element: member); | 1203 element: member); |
| 1204 } | 1204 } |
| 1205 emitExtraAccessors(member, builder); | 1205 emitExtraAccessors(member, builder); |
| 1206 } | 1206 } |
| 1207 | 1207 |
| 1208 String getReflectionName(Element element) { | 1208 String getReflectionName(Element element) { |
| 1209 if (!compiler.mirrorsEnabled) return null; | 1209 if (!compiler.mirrorsEnabled) return null; |
| 1210 String name = element.name.slowToString(); | 1210 String name = element.name.slowToString(); |
| 1211 if (element.isGetter()) return name; | 1211 if (element.isGetter()) return name; |
| 1212 if (element.isSetter()) return '$name='; | 1212 if (element.isSetter()) return '$name='; |
| 1213 if (element.isFunction()) { | 1213 if (element.isFunction() || element.isConstructor()) { |
| 1214 FunctionElement function = element; | 1214 FunctionElement function = element; |
| 1215 int requiredParameterCount = function.requiredParameterCount(compiler); | 1215 int requiredParameterCount = function.requiredParameterCount(compiler); |
| 1216 int optionalParameterCount = function.optionalParameterCount(compiler); | 1216 int optionalParameterCount = function.optionalParameterCount(compiler); |
| 1217 String suffix = '$name:$requiredParameterCount:$optionalParameterCount'; | 1217 String suffix = '$name:$requiredParameterCount:$optionalParameterCount'; |
| 1218 return (function.isConstructor()) ? 'new $suffix' : suffix; | 1218 return (function.isConstructor()) ? 'new $suffix' : suffix; |
| 1219 } | 1219 } |
| 1220 if (element.isGenerativeConstructorBody()) { | 1220 if (element.isGenerativeConstructorBody()) { |
| 1221 return null; | 1221 return null; |
| 1222 } | 1222 } |
| 1223 throw compiler.internalErrorOnElement( | 1223 throw compiler.internalErrorOnElement( |
| 1224 element, 'Do not know how to reflect on this'); | 1224 element, 'Do not know how to reflect on this $element'); |
| 1225 } | 1225 } |
| 1226 | 1226 |
| 1227 /** | 1227 /** |
| 1228 * Documentation wanted -- johnniwinther | 1228 * Documentation wanted -- johnniwinther |
| 1229 * | 1229 * |
| 1230 * Invariant: [classElement] must be a declaration element. | 1230 * Invariant: [classElement] must be a declaration element. |
| 1231 */ | 1231 */ |
| 1232 void emitInstanceMembers(ClassElement classElement, | 1232 void emitInstanceMembers(ClassElement classElement, |
| 1233 ClassBuilder builder) { | 1233 ClassBuilder builder) { |
| 1234 assert(invariant(classElement, classElement.isDeclaration)); | 1234 assert(invariant(classElement, classElement.isDeclaration)); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1647 emitInstanceMembers(classElement, builder); | 1647 emitInstanceMembers(classElement, builder); |
| 1648 } | 1648 } |
| 1649 emitIsTests(classElement, builder); | 1649 emitIsTests(classElement, builder); |
| 1650 | 1650 |
| 1651 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. | 1651 // TODO(ahe): This method (generateClass) should return a jsAst.Expression. |
| 1652 if (!buffer.isEmpty) { | 1652 if (!buffer.isEmpty) { |
| 1653 buffer.write(',$n$n'); | 1653 buffer.write(',$n$n'); |
| 1654 } | 1654 } |
| 1655 buffer.write('$className:$_'); | 1655 buffer.write('$className:$_'); |
| 1656 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); | 1656 buffer.write(jsAst.prettyPrint(builder.toObjectInitializer(), compiler)); |
| 1657 buffer.write(',$n$n"+${classElement.name.slowToString()}": 0'); | |
|
ngeoffray
2013/06/19 06:26:36
Unconditionally? So you're adding this extra for a
ahe
2013/06/19 07:20:29
Whoops.
| |
| 1657 } | 1658 } |
| 1658 | 1659 |
| 1659 bool get getterAndSetterCanBeImplementedByFieldSpec => true; | 1660 bool get getterAndSetterCanBeImplementedByFieldSpec => true; |
| 1660 | 1661 |
| 1661 /// If this is true then we can generate the noSuchMethod handlers at startup | 1662 /// If this is true then we can generate the noSuchMethod handlers at startup |
| 1662 /// time, instead of them being emitted as part of the Object class. | 1663 /// time, instead of them being emitted as part of the Object class. |
| 1663 bool get generateTrivialNsmHandlers => true; | 1664 bool get generateTrivialNsmHandlers => true; |
| 1664 | 1665 |
| 1665 int _selectorRank(Selector selector) { | 1666 int _selectorRank(Selector selector) { |
| 1666 int arity = selector.argumentCount * 3; | 1667 int arity = selector.argumentCount * 3; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1877 for (Element element in Elements.sortedByPosition(elements)) { | 1878 for (Element element in Elements.sortedByPosition(elements)) { |
| 1878 CodeBuffer buffer = bufferForElement(element, eagerBuffer); | 1879 CodeBuffer buffer = bufferForElement(element, eagerBuffer); |
| 1879 jsAst.Expression code = backend.generatedCode[element]; | 1880 jsAst.Expression code = backend.generatedCode[element]; |
| 1880 String name = namer.getName(element); | 1881 String name = namer.getName(element); |
| 1881 emitStaticFunction(buffer, name, code); | 1882 emitStaticFunction(buffer, name, code); |
| 1882 var metadata = buildMetadataFunction(element); | 1883 var metadata = buildMetadataFunction(element); |
| 1883 if (metadata != null) { | 1884 if (metadata != null) { |
| 1884 buffer.write(',$n$n"@$name":$_'); | 1885 buffer.write(',$n$n"@$name":$_'); |
| 1885 buffer.write(jsAst.prettyPrint(metadata, compiler)); | 1886 buffer.write(jsAst.prettyPrint(metadata, compiler)); |
| 1886 } | 1887 } |
| 1888 String reflectionName = getReflectionName(element); | |
| 1889 if (reflectionName != null) { | |
| 1890 buffer.write(',$n$n"+$reflectionName":${_}0'); | |
| 1891 } | |
| 1887 jsAst.Expression bailoutCode = backend.generatedBailoutCode[element]; | 1892 jsAst.Expression bailoutCode = backend.generatedBailoutCode[element]; |
| 1888 if (bailoutCode != null) { | 1893 if (bailoutCode != null) { |
| 1889 pendingElementsWithBailouts.remove(element); | 1894 pendingElementsWithBailouts.remove(element); |
| 1890 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); | 1895 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); |
| 1891 } | 1896 } |
| 1892 } | 1897 } |
| 1893 | 1898 |
| 1894 if (!pendingElementsWithBailouts.isEmpty) { | 1899 if (!pendingElementsWithBailouts.isEmpty) { |
| 1895 addComment('pendingElementsWithBailouts', eagerBuffer); | 1900 addComment('pendingElementsWithBailouts', eagerBuffer); |
| 1896 } | 1901 } |
| (...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3334 MessageKind.GENERIC.error({'text': message}), | 3339 MessageKind.GENERIC.error({'text': message}), |
| 3335 api.Diagnostic.WARNING); | 3340 api.Diagnostic.WARNING); |
| 3336 } | 3341 } |
| 3337 | 3342 |
| 3338 // TODO(ahe): This code should be integrated in finishClasses. | 3343 // TODO(ahe): This code should be integrated in finishClasses. |
| 3339 String getReflectionDataParser() { | 3344 String getReflectionDataParser() { |
| 3340 return ''' | 3345 return ''' |
| 3341 (function (reflectionData) { | 3346 (function (reflectionData) { |
| 3342 if (!init.libraries) init.libraries = []; | 3347 if (!init.libraries) init.libraries = []; |
| 3343 if (!init.mangledNames) init.mangledNames = {}; | 3348 if (!init.mangledNames) init.mangledNames = {}; |
| 3349 if (!init.mangledGlobalNames) init.mangledGlobalNames = {}; | |
| 3344 var libraries = init.libraries; | 3350 var libraries = init.libraries; |
| 3345 var mangledNames = init.mangledNames; | 3351 var mangledNames = init.mangledNames; |
| 3352 var mangledGlobalNames = init.mangledGlobalNames; | |
| 3346 var hasOwnProperty = Object.prototype.hasOwnProperty; | 3353 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 3347 var length = reflectionData.length; | 3354 var length = reflectionData.length; |
| 3348 for (var i = 0; i < length; i++) { | 3355 for (var i = 0; i < length; i++) { |
| 3349 var data = reflectionData[i]; | 3356 var data = reflectionData[i]; |
| 3350 var name = data[0]; | 3357 var name = data[0]; |
| 3351 var uri = data[1]; | 3358 var uri = data[1]; |
| 3352 var metadata = data[2]; | 3359 var metadata = data[2]; |
| 3353 var descriptor = data[3]; | 3360 var descriptor = data[3]; |
| 3354 var classes = []; | 3361 var classes = []; |
| 3355 var functions = []; | 3362 var functions = []; |
| 3356 for (var property in descriptor) { | 3363 for (var property in descriptor) { |
| 3357 if (!hasOwnProperty.call(descriptor, property)) continue; | 3364 if (!hasOwnProperty.call(descriptor, property)) continue; |
| 3358 var element = descriptor[property]; | 3365 var element = descriptor[property]; |
| 3359 if (property.substring(0, 1) == "@") { | 3366 var firstChar = property.substring(0, 1); |
| 3367 var previousProperty; | |
| 3368 if (firstChar == "+") { | |
| 3369 mangledGlobalNames[previousProperty] = property.substring(1); | |
| 3370 } else if (firstChar == "@") { | |
| 3360 property = property.substring(1); | 3371 property = property.substring(1); |
| 3361 ${namer.CURRENT_ISOLATE}[property]["${namer.metadataField}"] = element; | 3372 ${namer.CURRENT_ISOLATE}[property]["${namer.metadataField}"] = element; |
| 3362 } else if (typeof element === "function") { | 3373 } else if (typeof element === "function") { |
| 3363 ${namer.CURRENT_ISOLATE}[property] = element; | 3374 ${namer.CURRENT_ISOLATE}[previousProperty = property] = element; |
| 3364 functions.push(property); | 3375 functions.push(property); |
| 3365 } else { | 3376 } else { |
| 3377 previousProperty = property; | |
| 3366 var newDesc = {}; | 3378 var newDesc = {}; |
| 3367 var previousProp; | 3379 var previousProp; |
| 3368 for (var prop in element) { | 3380 for (var prop in element) { |
| 3369 if (!hasOwnProperty.call(element, prop)) continue; | 3381 if (!hasOwnProperty.call(element, prop)) continue; |
| 3370 var firstChar = prop.substring(0, 1); | 3382 firstChar = prop.substring(0, 1); |
| 3371 if (firstChar == "+") { | 3383 if (firstChar == "+") { |
| 3372 mangledNames[previousProp] = prop.substring(1); | 3384 mangledNames[previousProp] = prop.substring(1); |
| 3373 } else if (firstChar == "@" && prop != "@") { | 3385 } else if (firstChar == "@" && prop != "@") { |
| 3374 newDesc[prop.substring(1)]["${namer.metadataField}"] =''' | 3386 newDesc[prop.substring(1)]["${namer.metadataField}"] =''' |
| 3375 '''element[prop]; | 3387 '''element[prop]; |
| 3376 } else { | 3388 } else { |
| 3377 newDesc[previousProp = prop] = element[prop]; | 3389 newDesc[previousProp = prop] = element[prop]; |
| 3378 } | 3390 } |
| 3379 } | 3391 } |
| 3380 $classesCollector[property] = newDesc; | 3392 $classesCollector[property] = newDesc; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3393 | 3405 |
| 3394 const String HOOKS_API_USAGE = """ | 3406 const String HOOKS_API_USAGE = """ |
| 3395 // The code supports the following hooks: | 3407 // The code supports the following hooks: |
| 3396 // dartPrint(message) - if this function is defined it is called | 3408 // dartPrint(message) - if this function is defined it is called |
| 3397 // instead of the Dart [print] method. | 3409 // instead of the Dart [print] method. |
| 3398 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3410 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3399 // method will not be invoked directly. | 3411 // method will not be invoked directly. |
| 3400 // Instead, a closure that will invoke [main] is | 3412 // Instead, a closure that will invoke [main] is |
| 3401 // passed to [dartMainRunner]. | 3413 // passed to [dartMainRunner]. |
| 3402 """; | 3414 """; |
| OLD | NEW |