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 * 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 | 259 |
| 260 void emitStaticFunctions(StringBuffer buffer) { | 260 void emitStaticFunctions(StringBuffer buffer) { |
| 261 emitStaticFunctionsWithNamer(buffer, | 261 emitStaticFunctionsWithNamer(buffer, |
| 262 compiler.universe.generatedCode, | 262 compiler.universe.generatedCode, |
| 263 namer.isolatePropertyAccess); | 263 namer.isolatePropertyAccess); |
| 264 emitStaticFunctionsWithNamer(buffer, | 264 emitStaticFunctionsWithNamer(buffer, |
| 265 compiler.universe.generatedBailoutCode, | 265 compiler.universe.generatedBailoutCode, |
| 266 namer.isolateBailoutPropertyAccess); | 266 namer.isolateBailoutPropertyAccess); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void emitStaticFunctionGetters(StringBuffer buffer) { | |
| 270 Set<FunctionElement> functionsNeedingGetter = | |
| 271 compiler.universe.staticFunctionsNeedingGetter; | |
| 272 for (FunctionElement element in functionsNeedingGetter) { | |
| 273 FunctionElement callElement = | |
|
ngeoffray
2012/02/13 10:21:52
Please explain why you need to create a temporary
floitsch
2012/02/13 12:34:02
Done.
| |
| 274 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, | |
| 275 element, | |
| 276 null); | |
| 277 String staticName = namer.isolatePropertyAccess(element); | |
| 278 int parameterCount = element.parameterCount(compiler); | |
| 279 String invocationName = | |
| 280 namer.instanceMethodName(callElement.name, parameterCount); | |
| 281 buffer.add("$staticName.$invocationName = $staticName;\n"); | |
| 282 addParameterStubs(callElement, staticName, buffer); | |
| 283 } | |
| 284 } | |
| 285 | |
| 269 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { | 286 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { |
| 270 // Adds initializations inside the Isolate constructor. | 287 // Adds initializations inside the Isolate constructor. |
| 271 // Example: | 288 // Example: |
| 272 // function Isolate() { | 289 // function Isolate() { |
| 273 // this.staticNonFinal = Isolate.prototype.someVal; | 290 // this.staticNonFinal = Isolate.prototype.someVal; |
| 274 // ... | 291 // ... |
| 275 // } | 292 // } |
| 276 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; | 293 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; |
| 277 List<VariableElement> staticNonFinalFields = | 294 List<VariableElement> staticNonFinalFields = |
| 278 constants.getStaticNonFinalFieldsForEmission(); | 295 constants.getStaticNonFinalFieldsForEmission(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 367 |
| 351 String assembleProgram() { | 368 String assembleProgram() { |
| 352 measure(() { | 369 measure(() { |
| 353 StringBuffer buffer = new StringBuffer(); | 370 StringBuffer buffer = new StringBuffer(); |
| 354 buffer.add('function ${namer.ISOLATE}() {'); | 371 buffer.add('function ${namer.ISOLATE}() {'); |
| 355 emitStaticNonFinalFieldInitializations(buffer); | 372 emitStaticNonFinalFieldInitializations(buffer); |
| 356 buffer.add('}\n\n'); | 373 buffer.add('}\n\n'); |
| 357 emitClasses(buffer); | 374 emitClasses(buffer); |
| 358 emitNoSuchMethodCalls(buffer); | 375 emitNoSuchMethodCalls(buffer); |
| 359 emitStaticFunctions(buffer); | 376 emitStaticFunctions(buffer); |
| 377 emitStaticFunctionGetters(buffer); | |
| 360 emitStaticFinalFieldInitializations(buffer); | 378 emitStaticFinalFieldInitializations(buffer); |
| 361 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 379 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 362 Element main = compiler.mainApp.find(Compiler.MAIN); | 380 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 363 buffer.add('${namer.isolateAccess(main)}();\n'); | 381 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 364 compiler.assembledCode = buffer.toString(); | 382 compiler.assembledCode = buffer.toString(); |
| 365 }); | 383 }); |
| 366 return compiler.assembledCode; | 384 return compiler.assembledCode; |
| 367 } | 385 } |
| 368 } | 386 } |
| OLD | NEW |