| 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 // The static function does not have the correct name. Since |
| 274 // [addParameterStubs] use the name to create its stubs we simply |
| 275 // create a fake element with the correct name. |
| 276 // Note: the callElement will not have the correct modifiers (in case |
| 277 // of static functions) and will not have any enclosingElement. |
| 278 FunctionElement callElement = |
| 279 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, |
| 280 element, |
| 281 null); |
| 282 String staticName = namer.isolatePropertyAccess(element); |
| 283 int parameterCount = element.parameterCount(compiler); |
| 284 String invocationName = |
| 285 namer.instanceMethodName(callElement.name, parameterCount); |
| 286 buffer.add("$staticName.$invocationName = $staticName;\n"); |
| 287 addParameterStubs(callElement, staticName, buffer); |
| 288 } |
| 289 } |
| 290 |
| 269 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { | 291 void emitStaticNonFinalFieldInitializations(StringBuffer buffer) { |
| 270 // Adds initializations inside the Isolate constructor. | 292 // Adds initializations inside the Isolate constructor. |
| 271 // Example: | 293 // Example: |
| 272 // function Isolate() { | 294 // function Isolate() { |
| 273 // this.staticNonFinal = Isolate.prototype.someVal; | 295 // this.staticNonFinal = Isolate.prototype.someVal; |
| 274 // ... | 296 // ... |
| 275 // } | 297 // } |
| 276 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; | 298 CompileTimeConstantHandler constants = compiler.compileTimeConstantHandler; |
| 277 List<VariableElement> staticNonFinalFields = | 299 List<VariableElement> staticNonFinalFields = |
| 278 constants.getStaticNonFinalFieldsForEmission(); | 300 constants.getStaticNonFinalFieldsForEmission(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 372 |
| 351 String assembleProgram() { | 373 String assembleProgram() { |
| 352 measure(() { | 374 measure(() { |
| 353 StringBuffer buffer = new StringBuffer(); | 375 StringBuffer buffer = new StringBuffer(); |
| 354 buffer.add('function ${namer.ISOLATE}() {'); | 376 buffer.add('function ${namer.ISOLATE}() {'); |
| 355 emitStaticNonFinalFieldInitializations(buffer); | 377 emitStaticNonFinalFieldInitializations(buffer); |
| 356 buffer.add('}\n\n'); | 378 buffer.add('}\n\n'); |
| 357 emitClasses(buffer); | 379 emitClasses(buffer); |
| 358 emitNoSuchMethodCalls(buffer); | 380 emitNoSuchMethodCalls(buffer); |
| 359 emitStaticFunctions(buffer); | 381 emitStaticFunctions(buffer); |
| 382 emitStaticFunctionGetters(buffer); |
| 360 emitStaticFinalFieldInitializations(buffer); | 383 emitStaticFinalFieldInitializations(buffer); |
| 361 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 384 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 362 Element main = compiler.mainApp.find(Compiler.MAIN); | 385 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 363 buffer.add('${namer.isolateAccess(main)}();\n'); | 386 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 364 compiler.assembledCode = buffer.toString(); | 387 compiler.assembledCode = buffer.toString(); |
| 365 }); | 388 }); |
| 366 return compiler.assembledCode; | 389 return compiler.assembledCode; |
| 367 } | 390 } |
| 368 } | 391 } |
| OLD | NEW |