Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * Generates the code for all used classes in the program. Static fields (even | 6 * Generates the code for all used classes in the program. Static fields (even |
| 7 * in classes) are ignored, since they can be treated as non-class elements. | 7 * in classes) are ignored, since they can be treated as non-class elements. |
| 8 * | 8 * |
| 9 * The code for the containing (used) methods must exist in the [:universe:]. | 9 * The code for the containing (used) methods must exist in the [:universe:]. |
| 10 */ | 10 */ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 || member.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 45 || member.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 46 String codeBlock = compiler.universe.generatedCode[member]; | 46 String codeBlock = compiler.universe.generatedCode[member]; |
| 47 if (codeBlock !== null) { | 47 if (codeBlock !== null) { |
| 48 buffer.add('$prototype.${namer.getName(member)} = $codeBlock;\n'); | 48 buffer.add('$prototype.${namer.getName(member)} = $codeBlock;\n'); |
| 49 } | 49 } |
| 50 codeBlock = compiler.universe.generatedBailoutCode[member]; | 50 codeBlock = compiler.universe.generatedBailoutCode[member]; |
| 51 if (codeBlock !== null) { | 51 if (codeBlock !== null) { |
| 52 String name = namer.getBailoutName(member); | 52 String name = namer.getBailoutName(member); |
| 53 buffer.add('$prototype.$name = $codeBlock;\n'); | 53 buffer.add('$prototype.$name = $codeBlock;\n'); |
| 54 } | 54 } |
| 55 } else { | 55 } else if (member.kind === ElementKind.FIELD) { |
| 56 // TODO(ngeoffray): Have another class generate the code for the | 56 // TODO(ngeoffray): Have another class generate the code for the |
| 57 // fields. | 57 // fields. |
| 58 assert(member.kind === ElementKind.FIELD); | |
| 59 if (compiler.universe.invokedSetters.contains(member.name)) { | 58 if (compiler.universe.invokedSetters.contains(member.name)) { |
| 60 String setterName = namer.setterName(member.name); | 59 String setterName = namer.setterName(member.name); |
| 61 buffer.add('$prototype.$setterName = function(v){\n' + | 60 buffer.add('$prototype.$setterName = function(v){\n' + |
| 62 ' this.${namer.getName(member)} = v;\n}\n'); | 61 ' this.${namer.getName(member)} = v;\n}\n'); |
| 63 } | 62 } |
| 64 if (compiler.universe.invokedGetters.contains(member.name)) { | 63 if (compiler.universe.invokedGetters.contains(member.name)) { |
| 65 String getterName = namer.getterName(member.name); | 64 String getterName = namer.getterName(member.name); |
| 66 buffer.add('$prototype.$getterName = function(){\n' + | 65 buffer.add('$prototype.$getterName = function(){\n' + |
| 67 ' return this.${namer.getName(member)};\n}\n'); | 66 ' return this.${namer.getName(member)};\n}\n'); |
| 68 } | 67 } |
| 68 } else { | |
| 69 compiler.internalError('unexpected kind: "${member.kind}"', | |
| 70 element: member); | |
|
ngeoffray
2012/01/25 08:36:05
Because that's the only place it's needed, and bec
ahe
2012/01/25 08:56:24
I tried calling parseNode here, but noticed that I
ngeoffray
2012/01/25 09:03:59
Yeah, and I guess that's a bug: we're not putting
ahe
2012/01/25 09:07:14
I'm not sure what situation you have in mind here.
| |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 | 73 |
| 72 bool generateFieldInits(ClassElement classElement, | 74 bool generateFieldInits(ClassElement classElement, |
| 73 StringBuffer argumentsBuffer, | 75 StringBuffer argumentsBuffer, |
| 74 StringBuffer bodyBuffer) { | 76 StringBuffer bodyBuffer) { |
| 75 bool isFirst = true; | 77 bool isFirst = true; |
| 76 do { | 78 do { |
| 77 // TODO(floitsch): make sure there are no name clashes. | 79 // TODO(floitsch): make sure there are no name clashes. |
| 78 String className = namer.getName(classElement); | 80 String className = namer.getName(classElement); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 emitStaticFunctions(buffer); | 243 emitStaticFunctions(buffer); |
| 242 emitStaticFinalFieldInitializations(buffer); | 244 emitStaticFinalFieldInitializations(buffer); |
| 243 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 245 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 244 Element main = compiler.universe.find(Compiler.MAIN); | 246 Element main = compiler.universe.find(Compiler.MAIN); |
| 245 buffer.add('${namer.isolateAccess(main)}();\n'); | 247 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 246 compiler.assembledCode = buffer.toString(); | 248 compiler.assembledCode = buffer.toString(); |
| 247 }); | 249 }); |
| 248 return compiler.assembledCode; | 250 return compiler.assembledCode; |
| 249 } | 251 } |
| 250 } | 252 } |
| OLD | NEW |